directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r407088 - /directory/branches/elecharny/shared/ldap/src/main/java/org/apache/directory/shared/ldap/util/StringTools.java
Date Tue, 16 May 2006 21:57:17 GMT
Author: elecharny
Date: Tue May 16 14:56:56 2006
New Revision: 407088

URL: http://svn.apache.org/viewcvs?rev=407088&view=rev
Log:
Added support of Charset.getDefaultCharsetName() even if using jdk 1.4

Modified:
    directory/branches/elecharny/shared/ldap/src/main/java/org/apache/directory/shared/ldap/util/StringTools.java

Modified: directory/branches/elecharny/shared/ldap/src/main/java/org/apache/directory/shared/ldap/util/StringTools.java
URL: http://svn.apache.org/viewcvs/directory/branches/elecharny/shared/ldap/src/main/java/org/apache/directory/shared/ldap/util/StringTools.java?rev=407088&r1=407087&r2=407088&view=diff
==============================================================================
--- directory/branches/elecharny/shared/ldap/src/main/java/org/apache/directory/shared/ldap/util/StringTools.java
(original)
+++ directory/branches/elecharny/shared/ldap/src/main/java/org/apache/directory/shared/ldap/util/StringTools.java
Tue May 16 14:56:56 2006
@@ -17,12 +17,15 @@
 package org.apache.directory.shared.ldap.util;
 
 
+import java.io.ByteArrayOutputStream;
 import java.io.File;
+import java.io.OutputStreamWriter;
 import java.io.UnsupportedEncodingException;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.io.FileFilter;
+import java.nio.charset.Charset;
 import java.util.ArrayList;
 import java.util.regex.Pattern;
 import java.util.regex.PatternSyntaxException;
@@ -38,6 +41,11 @@
  */
 public class StringTools
 {
+    /** The default charset, because it's not provided by JDK 1.5 */
+    private static final String DEFAULT_CHARSET_JDK_1_4 = new OutputStreamWriter( new ByteArrayOutputStream()
).getEncoding();
+    private static final String DEFAULT_CHARSET_JDK_1_5 = Charset.defaultCharset().name();
+    private static final String JAVA_VERSION = System.getProperty( "java.version" );
+    
     /**
      * Trims several consecutive characters into one.
      * 
@@ -2261,5 +2269,20 @@
         }
 
         return sb.toString();
+    }
+
+    /**
+     * @return The default charset
+     */
+    public static String getDefaultCharsetName()
+    {
+        if ( JAVA_VERSION.startsWith( "1.4" ) )
+        {
+            return DEFAULT_CHARSET_JDK_1_4;
+        }
+        else
+        {
+            return DEFAULT_CHARSET_JDK_1_5;
+        }
     }
 }



Mime
View raw message