directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r358996 - /directory/asn1/trunk/codec/src/main/java/org/apache/asn1/codec/util/StringUtils.java
Date Sun, 25 Dec 2005 18:21:45 GMT
Author: elecharny
Date: Sun Dec 25 10:21:40 2005
New Revision: 358996

URL: http://svn.apache.org/viewcvs?rev=358996&view=rev
Log:
Added a utf8ToString() methods which take a new argument :
the nimber of bytes to be decoded.

Modified:
    directory/asn1/trunk/codec/src/main/java/org/apache/asn1/codec/util/StringUtils.java

Modified: directory/asn1/trunk/codec/src/main/java/org/apache/asn1/codec/util/StringUtils.java
URL: http://svn.apache.org/viewcvs/directory/asn1/trunk/codec/src/main/java/org/apache/asn1/codec/util/StringUtils.java?rev=358996&r1=358995&r2=358996&view=diff
==============================================================================
--- directory/asn1/trunk/codec/src/main/java/org/apache/asn1/codec/util/StringUtils.java (original)
+++ directory/asn1/trunk/codec/src/main/java/org/apache/asn1/codec/util/StringUtils.java Sun
Dec 25 10:21:40 2005
@@ -1371,6 +1371,29 @@
     }
 
     /**
+     * Return an UTF-8 encoded String
+     * @param bytes The byte array to be transformed to a String
+     * @param length The length of the byte array to be converted
+     * @return A String. 
+     */
+    public static String utf8ToString( byte[] bytes, int length )
+    {
+        if( bytes == null )
+        {
+            return "";
+        }
+
+        try
+        {
+            return new String( bytes, 0, length, "UTF-8" );
+        }
+        catch ( UnsupportedEncodingException uee )
+        {
+            return "";
+        }
+    }
+
+    /**
      * Return UTF-8 encoded byte[] representation of a String
      * @param string The string to be transformed to a byte array
      * @return The transformed byte array 



Mime
View raw message