Return-Path: Delivered-To: apmail-directory-commits-archive@www.apache.org Received: (qmail 23938 invoked from network); 16 May 2006 21:57:57 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 16 May 2006 21:57:57 -0000 Received: (qmail 2359 invoked by uid 500); 16 May 2006 21:57:53 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 2304 invoked by uid 500); 16 May 2006 21:57:53 -0000 Mailing-List: contact commits-help@directory.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@directory.apache.org Delivered-To: mailing list commits@directory.apache.org Received: (qmail 2290 invoked by uid 99); 16 May 2006 21:57:53 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 16 May 2006 14:57:53 -0700 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.29) with SMTP; Tue, 16 May 2006 14:57:52 -0700 Received: (qmail 23844 invoked by uid 65534); 16 May 2006 21:57:30 -0000 Message-ID: <20060516215730.23823.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commits@directory.apache.org From: elecharny@apache.org X-Mailer: svnmailer-1.0.8 X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N 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; + } } }