mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

Ludovic Poitou
02.45.2010 7bdcb41c0f62967ec42d552f6002577dfb7019ca
sdk/src/org/opends/sdk/ByteString.java
@@ -22,7 +22,7 @@
 * CDDL HEADER END
 *
 *
 *      Copyright 2009 Sun Microsystems, Inc.
 *      Copyright 2009-2010 Sun Microsystems, Inc.
 */
package org.opends.sdk;
@@ -30,6 +30,9 @@
import java.io.IOException;
import java.io.OutputStream;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.charset.Charset;
import java.util.logging.Level;
import com.sun.opends.sdk.util.StaticUtils;
@@ -144,6 +147,26 @@
  /**
   * Returns a byte string containing the UTF-8 encoded bytes of the provided
   * char array.
   *
   * @param chars
   *          The char array to use.
   * @return A byte string containing the UTF-8 encoded bytes of the provided
   *         char array.
   */
  public static ByteString valueOf(final char[] chars)
  {
    Charset utf8 = Charset.forName("UTF-8");
    ByteBuffer buffer = utf8.encode(CharBuffer.wrap(chars));
    byte[] bytes = new byte[buffer.remaining()];
    buffer.get(bytes);
    return wrap(bytes);
  }
  /**
   * Returns a byte string that wraps the provided byte array.
   * <p>
   * <b>NOTE:</b> this method takes ownership of the provided byte array and,
@@ -613,6 +636,23 @@
  /**
   * Returns the UTF-8 decoded char array representation of this byte sequence.
   *
   * @return The UTF-8 decoded char array representation of this byte sequence.
   */
  public char[] toCharArray()
  {
    Charset utf8 = Charset.forName("UTF-8");
    CharBuffer charBuffer = utf8
        .decode(ByteBuffer.wrap(buffer, offset, length));
    char[] chars = new char[charBuffer.remaining()];
    charBuffer.get(chars);
    return chars;
  }
  /**
   * Returns the integer value represented by the first four bytes of this byte
   * string in big-endian order.
   *