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

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

Introduction

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

Prototype

String UTF_16

To view the source code for org.apache.commons.lang3 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).

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

Usage

From source file:com.smartling.api.sdk.util.HttpUtils.java

private StringResponse inputStreamToString(final InputStream inputStream, final String encoding,
        final int httpCode) throws IOException {
    final byte[] contentsRaw = IOUtils.toByteArray(inputStream);
    // unless UTF-16 explicitly specified, use default UTF-8 encoding.
    final String responseEncoding = (null == encoding || !encoding.toUpperCase().contains(CharEncoding.UTF_16)
            ? CharEncoding.UTF_8//from   w w  w.  j av  a  2s . com
            : CharEncoding.UTF_16);
    final String contents = new String(contentsRaw, responseEncoding);
    return new StringResponse(contents, contentsRaw, responseEncoding, httpCode == HttpStatus.SC_OK);
}