From commits-return-10586-apmail-directory-commits-archive=directory.apache.org@directory.apache.org Thu Oct 05 09:32:53 2006 Return-Path: Delivered-To: apmail-directory-commits-archive@www.apache.org Received: (qmail 91118 invoked from network); 5 Oct 2006 09:32:52 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 5 Oct 2006 09:32:52 -0000 Received: (qmail 4349 invoked by uid 500); 5 Oct 2006 09:32:52 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 4277 invoked by uid 500); 5 Oct 2006 09:32:52 -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 4253 invoked by uid 99); 5 Oct 2006 09:32:51 -0000 Received: from idunn.apache.osuosl.org (HELO idunn.apache.osuosl.org) (140.211.166.84) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 05 Oct 2006 02:32:51 -0700 X-ASF-Spam-Status: No, hits=-9.4 required=5.0 tests=ALL_TRUSTED,NO_REAL_NAME Received: from [140.211.166.113] ([140.211.166.113:50752] helo=eris.apache.org) by idunn.apache.osuosl.org (ecelerity 2.1.1.8 r(12930)) with ESMTP id 02/22-20288-721D4254 for ; Thu, 05 Oct 2006 02:32:28 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id DB6C71A981D; Thu, 5 Oct 2006 02:32:05 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r453160 - /directory/trunks/shared/asn1/src/main/java/org/apache/directory/shared/asn1/util/Asn1StringUtils.java Date: Thu, 05 Oct 2006 09:32:05 -0000 To: commits@directory.apache.org From: elecharny@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20061005093205.DB6C71A981D@eris.apache.org> X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: elecharny Date: Thu Oct 5 02:32:04 2006 New Revision: 453160 URL: http://svn.apache.org/viewvc?view=rev&rev=453160 Log: Added the asciiStringToBytes method to efficiently generate byte[] for attribute type, which are supposed to be ascii only Modified: directory/trunks/shared/asn1/src/main/java/org/apache/directory/shared/asn1/util/Asn1StringUtils.java Modified: directory/trunks/shared/asn1/src/main/java/org/apache/directory/shared/asn1/util/Asn1StringUtils.java URL: http://svn.apache.org/viewvc/directory/trunks/shared/asn1/src/main/java/org/apache/directory/shared/asn1/util/Asn1StringUtils.java?view=diff&rev=453160&r1=453159&r2=453160 ============================================================================== --- directory/trunks/shared/asn1/src/main/java/org/apache/directory/shared/asn1/util/Asn1StringUtils.java (original) +++ directory/trunks/shared/asn1/src/main/java/org/apache/directory/shared/asn1/util/Asn1StringUtils.java Thu Oct 5 02:32:04 2006 @@ -37,6 +37,11 @@ private static final byte[] HEX_CHAR = new byte[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; + /** + * The empty byte[] + */ + public static final byte[] EMPTY_BYTES = new byte[] + {}; // ~ Methods // ------------------------------------------------------------------------------------ @@ -104,5 +109,29 @@ return new byte[] {}; } + } + + /** + * Thansform an array of ASCII bytes to a string. the byte array should contains + * only values in [0, 127]. + * + * @param bytes The byte array to transform + * @return The resulting string + */ + public static byte[] asciiStringToByte( String string ) + { + if ( ( string == null ) || ( string.length() == 0 ) ) + { + return EMPTY_BYTES; + } + + byte[] result = new byte[string.length()]; + + for ( int i = 0; i < result.length; i++ ) + { + result[i] = (byte)string.charAt( i ); + } + + return result; } }