Java Code Examples for com.google.common.base.Charsets#UTF_16

The following examples show how to use com.google.common.base.Charsets#UTF_16 . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: InputRowParserSerdeTest.java    From druid-api with Apache License 2.0 6 votes vote down vote up
@Test
public void testStringInputRowParserSerdeMultiCharset() throws Exception
{
  Charset[] testCharsets = {
      Charsets.US_ASCII, Charsets.ISO_8859_1, Charsets.UTF_8,
      Charsets.UTF_16BE, Charsets.UTF_16LE, Charsets.UTF_16
  };

  for (Charset testCharset : testCharsets) {
    InputRow parsed = testCharsetParseHelper(testCharset);
    Assert.assertEquals(ImmutableList.of("foo", "bar"), parsed.getDimensions());
    Assert.assertEquals(ImmutableList.of("x"), parsed.getDimension("foo"));
    Assert.assertEquals(ImmutableList.of("y"), parsed.getDimension("bar"));
    Assert.assertEquals(new DateTime("3000").getMillis(), parsed.getTimestampFromEpoch());
  }
}
 
Example 2
Source File: InputStreamCopierTest.java    From ExpectIt with Apache License 2.0 5 votes vote down vote up
@Test
public void testEcho2() throws ExecutionException, InterruptedException, IOException {
    final Appendable echo = mock(Appendable.class);
    final Charset utf16 = Charsets.UTF_16;
    final InputStreamCopier copier =
            new InputStreamCopier(channel, input, DEFAULT_BUFFER_SIZE, echo, utf16, false);
    executor.submit(copier).get();
    final String string = new String(toByteArray(resource), utf16);
    verify(echo).append(string);
}
 
Example 3
Source File: ByteBufferReplacer.java    From buck with Apache License 2.0 5 votes vote down vote up
private static byte[] getBytes(String str, Charset charset) {
  byte[] bytes = str.getBytes(charset);

  // Strip off the byte-order-markers for UTF-16.
  if (charset == Charsets.UTF_16) {
    bytes = Arrays.copyOfRange(bytes, 2, bytes.length);
  }

  return bytes;
}
 
Example 4
Source File: StringFunctionHelpers.java    From dremio-oss with Apache License 2.0 4 votes vote down vote up
public static String toStringFromUTF16(int start, int end, ArrowBuf buffer) {
  byte[] buf = new byte[end - start];
  buffer.getBytes(start, buf, 0, end - start);
  return new String(buf, Charsets.UTF_16);
}