directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
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 GMT
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;
     }
 }



Mime
View raw message