Example usage for org.apache.commons.codec Charsets UTF_16

List of usage examples for org.apache.commons.codec Charsets UTF_16

Introduction

In this page you can find the example usage for org.apache.commons.codec Charsets UTF_16.

Prototype

Charset UTF_16

To view the source code for org.apache.commons.codec Charsets UTF_16.

Click Source Link

Document

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

Every implementation of the Java platform is required to support this character encoding.

Usage

From source file:com.anrisoftware.prefdialog.csvimportdialog.panelproperties.panelproperties.CsvPanelPropertiesModule.java

@SuppressWarnings("deprecation")
@Provides//  w w  w  .  j a  v a2 s . co  m
@Singleton
@Named("charsetDefaults")
Collection<Charset> getCharsetDefaults() {
    List<Charset> list = new ArrayList<Charset>();
    list.add(Charsets.UTF_8);
    list.add(Charsets.UTF_16);
    list.add(Charsets.UTF_16BE);
    list.add(Charsets.UTF_16LE);
    list.add(Charsets.US_ASCII);
    list.add(Charsets.ISO_8859_1);
    return list;
}

From source file:com.yhspy.zbartest.StringUtils.java

/**
 * Encodes the given string into a sequence of bytes using the UTF-16 charset, storing the result into a new byte
 * array.//www  .j  a v a  2 s.c  om
 *
 * @param string
 *            the String to encode, may be {@code null}
 * @return encoded bytes, or {@code null} if the input string was {@code null}
 * @throws NullPointerException
 *             Thrown if {@link Charsets#UTF_16} is not initialized, which should never happen since it is
 *             required by the Java platform specification.
 * @since As of 1.7, throws {@link NullPointerException} instead of UnsupportedEncodingException
 * @see <a href="http://download.oracle.com/javase/6/docs/api/java/nio/charset/Charset.html">Standard charsets</a>
 * @see #getBytesUnchecked(String, String)
 */
public static byte[] getBytesUtf16(final String string) {
    return getBytes(string, Charsets.UTF_16);
}

From source file:com.yhspy.zbartest.StringUtils.java

/**
 * Constructs a new <code>String</code> by decoding the specified array of bytes using the UTF-16 charset.
 *
 * @param bytes//w w w . j av a  2 s  .  c  o m
 *            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} if the input byte array was {@code null}.
 * @throws NullPointerException
 *             Thrown if {@link Charsets#UTF_16} is not initialized, which should never happen since it is
 *             required by the Java platform specification.
 * @since As of 1.7, throws {@link NullPointerException} instead of UnsupportedEncodingException
 */
public static String newStringUtf16(final byte[] bytes) {
    return new String(bytes, Charsets.UTF_16);
}

From source file:org.apache.rocketmq.mysql.schema.column.StringColumnParser.java

@Override
public Object getValue(Object value) {

    if (value == null) {
        return null;
    }/* w ww .j  a  v a2 s  .com*/

    if (value instanceof String) {
        return value;
    }

    byte[] bytes = (byte[]) value;

    switch (charset) {
    case "utf8":
    case "utf8mb4":
        return new String(bytes, Charsets.UTF_8);
    case "latin1":
    case "ascii":
        return new String(bytes, Charsets.ISO_8859_1);
    case "ucs2":
        return new String(bytes, Charsets.UTF_16);
    default:
        return new String(bytes, Charsets.toCharset(charset));

    }
}