Return-Path: Delivered-To: apmail-directory-commits-archive@www.apache.org Received: (qmail 44546 invoked from network); 20 Jan 2011 17:38:35 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 20 Jan 2011 17:38:35 -0000 Received: (qmail 47336 invoked by uid 500); 20 Jan 2011 17:38:35 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 47283 invoked by uid 500); 20 Jan 2011 17:38:34 -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 47272 invoked by uid 99); 20 Jan 2011 17:38:33 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 20 Jan 2011 17:38:33 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 20 Jan 2011 17:38:31 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 6CA1023889DA; Thu, 20 Jan 2011 17:38:10 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1061409 - in /directory/shared/trunk: ldap/src/main/java/org/apache/directory/shared/ldap/util/StringTools.java util/src/main/java/org/apache/directory/shared/util/Strings.java Date: Thu, 20 Jan 2011 17:38:10 -0000 To: commits@directory.apache.org From: akarasulu@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110120173810.6CA1023889DA@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: akarasulu Date: Thu Jan 20 17:38:09 2011 New Revision: 1061409 URL: http://svn.apache.org/viewvc?rev=1061409&view=rev Log: fix reference to Hex and prepare to move some methods to Strings Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/StringTools.java directory/shared/trunk/util/src/main/java/org/apache/directory/shared/util/Strings.java Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/StringTools.java URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/StringTools.java?rev=1061409&r1=1061408&r2=1061409&view=diff ============================================================================== --- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/StringTools.java (original) +++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/StringTools.java Thu Jan 20 17:38:09 2011 @@ -37,7 +37,6 @@ import java.util.regex.PatternSyntaxExce import javax.naming.InvalidNameException; -import org.apache.directory.shared.asn1.Hex; import org.apache.directory.shared.i18n.I18n; import org.apache.directory.shared.ldap.entry.BinaryValue; import org.apache.directory.shared.ldap.entry.StringValue; @@ -1686,7 +1685,7 @@ public final class StringTools /** * Test if the current character is equal to a specific character. * - * @param string The String which contains the data + * @param bytes The String which contains the data * @param index Current position in the string * @param car The character we want to compare with the current string * position @@ -1830,7 +1829,7 @@ public final class StringTools * Check if the current byte is an Hex Char * <hex> ::= [0x30-0x39] | [0x41-0x46] | [0x61-0x66] * - * @param byte The byte we want to check + * @param b The byte we want to check * @return true if the current byte is a Hex byte */ public static boolean isHex( byte b ) @@ -3605,6 +3604,37 @@ public final class StringTools } + /** Used to build output as Hex */ + private static final char[] HEX_DIGITS = + { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' }; + + + /** + * Converts an array of bytes into an array of characters representing the + * hexidecimal values of each byte in order. The returned array will be + * double the length of the passed array, as it takes two characters to + * represent any given byte. + * + * @param data a byte[] to convert to Hex characters + * @return A char[] containing hexidecimal characters + */ + public static char[] encodeHex( byte[] data ) + { + int l = data.length; + + char[] out = new char[l << 1]; + + // two characters form the hex value. + for ( int i = 0, j = 0; i < l; i++ ) + { + out[j++] = HEX_DIGITS[( 0xF0 & data[i] ) >>> 4]; + out[j++] = HEX_DIGITS[0x0F & data[i]]; + } + + return out; + } + + /** * converts the bytes of a UUID to string * @@ -3618,7 +3648,7 @@ public final class StringTools return "Invalid UUID"; } - char[] hex = Hex.encodeHex( bytes ); + char[] hex = encodeHex( bytes ); StringBuffer sb = new StringBuffer(); sb.append( hex, 0, 8 ); sb.append( '-' ); Modified: directory/shared/trunk/util/src/main/java/org/apache/directory/shared/util/Strings.java URL: http://svn.apache.org/viewvc/directory/shared/trunk/util/src/main/java/org/apache/directory/shared/util/Strings.java?rev=1061409&r1=1061408&r2=1061409&view=diff ============================================================================== --- directory/shared/trunk/util/src/main/java/org/apache/directory/shared/util/Strings.java (original) +++ directory/shared/trunk/util/src/main/java/org/apache/directory/shared/util/Strings.java Thu Jan 20 17:38:09 2011 @@ -45,4 +45,8 @@ public final class Strings // ~ Static fields/initializers // ----------------------------------------------------------------- + /** Hex chars */ + private static final byte[] HEX_CHAR = new byte[] + { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; + }