directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From trus...@apache.org
Subject svn commit: r393730 - in /directory/trunks/mina/core/src: main/java/org/apache/mina/filter/codec/textline/TextLineCodecFactory.java main/java/org/apache/mina/util/CharsetUtil.java test/java/org/apache/mina/util/CharsetUtilTest.java
Date Thu, 13 Apr 2006 06:28:48 GMT
Author: trustin
Date: Wed Apr 12 23:28:44 2006
New Revision: 393730

URL: http://svn.apache.org/viewcvs?rev=393730&view=rev
Log:
Fixed issue: DIRMINA-207 (Charset.getDefaultEncoding doesn't work with JDK 1.6.0-beta2)
* Removed explicit version check

Modified:
    directory/trunks/mina/core/src/main/java/org/apache/mina/filter/codec/textline/TextLineCodecFactory.java
    directory/trunks/mina/core/src/main/java/org/apache/mina/util/CharsetUtil.java
    directory/trunks/mina/core/src/test/java/org/apache/mina/util/CharsetUtilTest.java

Modified: directory/trunks/mina/core/src/main/java/org/apache/mina/filter/codec/textline/TextLineCodecFactory.java
URL: http://svn.apache.org/viewcvs/directory/trunks/mina/core/src/main/java/org/apache/mina/filter/codec/textline/TextLineCodecFactory.java?rev=393730&r1=393729&r2=393730&view=diff
==============================================================================
--- directory/trunks/mina/core/src/main/java/org/apache/mina/filter/codec/textline/TextLineCodecFactory.java
(original)
+++ directory/trunks/mina/core/src/main/java/org/apache/mina/filter/codec/textline/TextLineCodecFactory.java
Wed Apr 12 23:28:44 2006
@@ -44,7 +44,7 @@
      */
     public TextLineCodecFactory()
     {
-        this( Charset.forName( CharsetUtil.getDefaultEncoding() ) );
+        this( Charset.forName( CharsetUtil.getDefaultCharsetName() ) );
     }
     
     /**

Modified: directory/trunks/mina/core/src/main/java/org/apache/mina/util/CharsetUtil.java
URL: http://svn.apache.org/viewcvs/directory/trunks/mina/core/src/main/java/org/apache/mina/util/CharsetUtil.java?rev=393730&r1=393729&r2=393730&view=diff
==============================================================================
--- directory/trunks/mina/core/src/main/java/org/apache/mina/util/CharsetUtil.java (original)
+++ directory/trunks/mina/core/src/main/java/org/apache/mina/util/CharsetUtil.java Wed Apr
12 23:28:44 2006
@@ -36,48 +36,26 @@
 {
     public static final Logger log = LoggerFactory.getLogger( CharsetUtil.class );
     
-    
-    public static final String getDefaultEncoding()
+    public static final String getDefaultCharsetName()
     {
-        String encoding = null;
-        String version = System.getProperty( "java.version" );
-        
-        if ( version.startsWith( "1.5" ) || version.startsWith( "5.0" ) )
+        // Use reflection here to be able to compile mina with jdk 1.4.
+        try
         {
-            // Use reflection here to be able to compile mina with jdk 1.4
-            try
-            {
-                Class charsetClass = Class.forName( "java.nio.charset.Charset" );
-                Object charSet = charsetClass.getMethod( "defaultCharset", null ).invoke(
null, null );
-                encoding = ( String ) charsetClass.getMethod( "name", null ).invoke( charSet,
null );
-            }
-            catch ( Exception e )
-            {
-                log.error( "Failed to call java.nio.charset.Charset.defaultCharset().name()
on JDK 1.5" );
-                throw new RuntimeException( e );
-            }
+            Class charsetClass = Class.forName( "java.nio.charset.Charset" );
+            Object charSet = charsetClass.getMethod( "defaultCharset", null ).invoke( null,
null );
+            return ( String ) charsetClass.getMethod( "name", null ).invoke( charSet, null
);
         }
-        else if ( version.startsWith( "1.4" ) )
+        catch ( Exception e )
         {
-            OutputStreamWriter writer = new OutputStreamWriter( new ByteArrayOutputStream()
);
-            encoding = writer.getEncoding();
         }
-        else if ( version.startsWith( "1.3" ) )
-        {
-            log.warn( "Character encoding determined in non-standard manner for JDK 1.3"
);
-            encoding = System.getProperty( "file.encoding" );
-        }
-        else
-        {
-            throw new IllegalStateException( "JDK version is not compatible." );
-        }
-        
-        return encoding;
-    }
 
+        // Try to use OutputStreamWriter instead.
+        OutputStreamWriter writer = new OutputStreamWriter( new ByteArrayOutputStream() );
+        return writer.getEncoding();
+    }
 
     public static Charset getDefaultCharset()
     {
-        return Charset.forName( getDefaultEncoding() );
+        return Charset.forName( getDefaultCharsetName() );
     }
 }

Modified: directory/trunks/mina/core/src/test/java/org/apache/mina/util/CharsetUtilTest.java
URL: http://svn.apache.org/viewcvs/directory/trunks/mina/core/src/test/java/org/apache/mina/util/CharsetUtilTest.java?rev=393730&r1=393729&r2=393730&view=diff
==============================================================================
--- directory/trunks/mina/core/src/test/java/org/apache/mina/util/CharsetUtilTest.java (original)
+++ directory/trunks/mina/core/src/test/java/org/apache/mina/util/CharsetUtilTest.java Wed
Apr 12 23:28:44 2006
@@ -28,10 +28,10 @@
  */
 public class CharsetUtilTest extends TestCase
 {
-    public void testGetDefaultEncoding()
+    public void testGetDefaultCharsetName()
     {
         // @todo How the heck do I test this so it works on all machines running test?
-        String encoding = CharsetUtil.getDefaultEncoding();
+        String encoding = CharsetUtil.getDefaultCharsetName();
         assertNotNull( encoding );
     }
 }



Mime
View raw message