logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rpo...@apache.org
Subject svn commit: r1481069 - /logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/layout/AbstractStringLayout.java
Date Fri, 10 May 2013 16:01:11 GMT
Author: rpopma
Date: Fri May 10 16:01:11 2013
New Revision: 1481069

URL: http://svn.apache.org/r1481069
Log:
findbugs charset fix: removed Java 5 support

Modified:
    logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/layout/AbstractStringLayout.java

Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/layout/AbstractStringLayout.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/layout/AbstractStringLayout.java?rev=1481069&r1=1481068&r2=1481069&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/layout/AbstractStringLayout.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/layout/AbstractStringLayout.java
Fri May 10 16:01:11 2013
@@ -16,11 +16,10 @@
  */
 package org.apache.logging.log4j.core.layout;
 
-import org.apache.logging.log4j.core.LogEvent;
-
-import java.io.UnsupportedEncodingException;
 import java.nio.charset.Charset;
 
+import org.apache.logging.log4j.core.LogEvent;
+
 /**
  * Abstract base class for Layouts that result in a String.
  */
@@ -31,19 +30,8 @@ public abstract class AbstractStringLayo
      */
     private final Charset charset;
 
-    private final StringEncoder encoder;
-
     protected AbstractStringLayout(final Charset charset) {
         this.charset = charset;
-        boolean useClass = false;
-        try {
-            if (String.class.getMethod("getBytes", new Class[] {Charset.class}) != null)
{
-                useClass = true;
-            }
-        } catch (final NoSuchMethodException ex) {
-            // Not JDK 6 or greater.
-        }
-        encoder = useClass ? new ClassEncoder() : new NameEncoder();
     }
 
     /**
@@ -54,7 +42,7 @@ public abstract class AbstractStringLayo
      */
     @Override
     public byte[] toByteArray(final LogEvent event) {
-        return encoder.getBytes(toSerializable(event));
+        return toSerializable(event).getBytes(charset);
     }
 
     /**
@@ -68,37 +56,4 @@ public abstract class AbstractStringLayo
     protected Charset getCharset() {
         return charset;
     }
-
-    /**
-     * Encoder interface to support Java 5 and Java 6+.
-     */
-    private interface StringEncoder {
-
-        byte[] getBytes(String str);
-    }
-
-    /**
-     * JDK 6 or greater.
-     */
-    private class ClassEncoder implements StringEncoder {
-        @Override
-        public byte[] getBytes(final String str) {
-            return str.getBytes(charset);
-        }
-    }
-
-    /**
-     * JDK 5.
-     */
-    private class NameEncoder implements StringEncoder {
-        @Override
-        public byte[] getBytes(final String str) {
-            try {
-                return str.getBytes(charset.name());
-            } catch (final UnsupportedEncodingException ex) {
-                // This shouldn't ever happen since an invalid Charset would never have been
created.
-                return str.getBytes();
-            }
-        }
-    }
 }



Mime
View raw message