| | |
| | | * CDDL HEADER END |
| | | * |
| | | * |
| | | * Copyright 2009 Sun Microsystems, Inc. |
| | | * Copyright 2009-2010 Sun Microsystems, Inc. |
| | | */ |
| | | package org.opends.sdk; |
| | | |
| | |
| | | |
| | | 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; |
| | |
| | | |
| | | |
| | | /** |
| | | * 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, |
| | |
| | | |
| | | |
| | | /** |
| | | * 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. |
| | | * |