You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2013/10/03 07:06:09 UTC
svn commit: r1528717 -
/directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/util/Strings.java
Author: elecharny
Date: Thu Oct 3 05:06:08 2013
New Revision: 1528717
URL: http://svn.apache.org/r1528717
Log:
Forgot to commit the addition of a utf8ToStrin(ByteBuffer) method
Modified:
directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/util/Strings.java
Modified: directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/util/Strings.java
URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/util/Strings.java?rev=1528717&r1=1528716&r2=1528717&view=diff
==============================================================================
--- directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/util/Strings.java (original)
+++ directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/util/Strings.java Thu Oct 3 05:06:08 2013
@@ -21,6 +21,7 @@ package org.apache.directory.mavibot.btr
import java.io.UnsupportedEncodingException;
+import java.nio.ByteBuffer;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -224,6 +225,34 @@ public final class Strings
* Return an UTF-8 encoded String
*
* @param bytes The byte array to be transformed to a String
+ * @return A String.
+ */
+ public static String utf8ToString( ByteBuffer bytes )
+ {
+ if ( bytes == null )
+ {
+ return "";
+ }
+
+ char[] chars = new char[bytes.limit()];
+ int pos = 0;
+
+ byte b;
+
+ do
+ {
+ chars[pos++] = ( char ) UTF8[bytes.get()];
+ }
+ while ( bytes.position() < bytes.limit() );
+
+ return new String( chars );
+ }
+
+
+ /**
+ * 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.
*/