Example usage for org.apache.commons.lang CharEncoding UTF_16

List of usage examples for org.apache.commons.lang CharEncoding UTF_16

Introduction

In this page you can find the example usage for org.apache.commons.lang CharEncoding UTF_16.

Prototype

String UTF_16

To view the source code for org.apache.commons.lang CharEncoding UTF_16.

Click Source Link

Document

Sixteen-bit Unicode Transformation Format, byte order specified by a mandatory initial byte-order mark (either order accepted on input, big-endian used on output).

Usage

From source file:com.cmcc.util.StringUtils.java

/**
 * Encodes the given string into a sequence of bytes using the UTF-16 charset, storing the result into a new byte
 * array./* w ww .  ja va 2s .c  om*/
 * 
 * @param string
 *            the String to encode, may be <code>null</code>
 * @return encoded bytes, or <code>null</code> if the input string was <code>null</code>
 * @throws IllegalStateException
 *             Thrown when the charset is missing, which should be never according the the Java specification.
 * @see <a href="http://download.oracle.com/javase/1.5.0/docs/api/java/nio/charset/Charset.html">Standard charsets</a>
 * @see #getBytesUnchecked(String, String)
 */
public static byte[] getBytesUtf16(String string) {
    return StringUtils.getBytesUnchecked(string, CharEncoding.UTF_16);
}

From source file:com.cmcc.util.StringUtils.java

/**
 * Constructs a new <code>String</code> by decoding the specified array of bytes using the UTF-16 charset.
 * /*from  ww  w  . j  a  v a 2s  .  co  m*/
 * @param bytes
 *            The bytes to be decoded into characters
 * @return A new <code>String</code> decoded from the specified array of bytes using the UTF-16 charset
 *         or <code>null</code> if the input byte array was <code>null</code>.
 * @throws IllegalStateException
 *             Thrown when a {@link UnsupportedEncodingException} is caught, which should never happen since the
 *             charset is required.
 */
public static String newStringUtf16(byte[] bytes) {
    return StringUtils.newString(bytes, CharEncoding.UTF_16);
}

From source file:org.eclipse.gyrex.p2.internal.installer.InstallLog.java

/**
 * Creates a new instance.//from ww  w.j  a va 2s.c  o m
 * 
 * @param shaHex
 * @throws IOException
 */
public InstallLog(final String sessionId) throws IOException {
    this.sessionId = sessionId;
    creationDate = new Date();

    final IPath logsFolder = PackageInstallState.getBaseLocation().append("logs");
    final String baseName = "install-" + DateFormatUtils.ISO_DATE_FORMAT.format(creationDate);

    // create new log file
    final File logFile = createNewLog(logsFolder, baseName);
    if (null == logFile) {
        throw new IllegalStateException("unable to create new log file; file count limit exceeded");
    }
    this.logFile = logFile;
    logFileWriter = new PrintWriter(new FileWriterWithEncoding(logFile, CharEncoding.UTF_16));

    // write header
    writeHeader();
}

From source file:org.marketcetera.util.unicode.UnicodeCharsetTest.java

@Test
public void utf16() throws Exception {
    single(UTF16BE, CharEncoding.UTF_16BE, COMBO_UTF16BE);
    single(UTF16LE, CharEncoding.UTF_16LE, COMBO_UTF16LE);

    byte[] dataOut = ArrayUtils.addAll(Signature.UTF16BE.getMark(), COMBO_UTF16BE);
    singlePrefix(UTF16, CharEncoding.UTF_16, COMBO_UTF16BE, dataOut);
    singlePrefix(UTF16, CharEncoding.UTF_16, ArrayUtils.addAll(Signature.UTF16BE.getMark(), COMBO_UTF16BE),
            dataOut);/*ww w.  j a  va  2  s  .  co  m*/
    singlePrefix(UTF16, CharEncoding.UTF_16, ArrayUtils.addAll(Signature.UTF16LE.getMark(), COMBO_UTF16LE),
            dataOut);
}