- Add the Codota plugin to your IDE and get smart completions
private void myMethod () {Connection c =
DataSource dataSource;dataSource.getConnection()
String url;DriverManager.getConnection(url)
IdentityDatabaseUtil.getDBConnection()
- Smart code suggestions by Codota
}
public static byte[] encode(char[] chars) { return encode(chars, 0, chars.length); }
public void toBytes(Supplier<byte[]> bytesSupplier, UTF8.BytesConsumer bytesConsumer) { UTF8.encode(buffer, 0, length, bytesSupplier, bytesConsumer); }
public static byte[] encode(char[] chars) { return encode(chars, 0, chars.length); }
public void toBytes(Supplier<byte[]> bytesSupplier, UTF8.BytesConsumer bytesConsumer) { UTF8.encode(buffer, 0, length, bytesSupplier, bytesConsumer); }
public static byte[] encodeAndTrim(char[] chars, int off, int length, byte[] bytes) { int l = encode(chars, off, length, bytes); return Arrays.copyOf(bytes, l); }
public static byte[] encodeAndTrim(char[] chars, int off, int length, byte[] bytes) { int l = encode(chars, off, length, bytes); return Arrays.copyOf(bytes, l); }
@Override public Writer append(char c) throws IOException { if (c < 128) { out.write((byte) c); } else { int l = UTF8.encode(c, bytes, 0); out.write(bytes, 0, l); } return this; }
@Override public void write(char[] chars, int off, int len) throws IOException { int limit = len + off; for (int i = off; i < limit; i += batchSize) { int l = UTF8.encode(chars, off, Math.min(limit - off, batchSize), bytes); out.write(bytes, 0, l); } }
@Override public Writer append(char c) throws IOException { if (c < 128) { out.write((byte) c); } else { int l = UTF8.encode(c, bytes, 0); out.write(bytes, 0, l); } return this; }
@Override public void write(char[] chars, int off, int len) throws IOException { int limit = len + off; for (int i = off; i < limit; i += batchSize) { int l = UTF8.encode(chars, off, Math.min(limit - off, batchSize), bytes); out.write(bytes, 0, l); } }
public static byte[] encode(char[] chars, int off, int length) { byte[] bytes = new byte[count(chars, off, length)]; encode(chars, off, length, bytes); return bytes; }
public static byte[] encode(char[] chars, int off, int length) { byte[] bytes = new byte[count(chars, off, length)]; encode(chars, off, length, bytes); return bytes; }
@Test public void encode() { char[] chars = new char[1]; Charset utf8 = Charset.forName("UTF-8"); for (char i = 0; i < Character.MAX_VALUE; i++) { chars[0] = i; Assert.assertArrayEquals("fails on " + (int) i, String.valueOf(i).getBytes(utf8), UTF8.encode(chars)); } }
@Test public void encode_surrogates() { char[] chars = new char[2]; Charset utf8 = Charset.forName("UTF-8"); for (char i = '\uD800'; i < '\uDC00'; i++) { chars[0] = i; for (char j = '\uDC00'; j < '\uE000'; j++) { chars[1] = j; Assert.assertArrayEquals("fails on " + (int) i + " " + (int) j, new String(chars).getBytes(utf8), UTF8.encode(chars)); } } }
private void test_supplier(final int bufferSize) throws UnsupportedEncodingException { String s = "€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€"; char[] chars = s.toCharArray(); final ByteArrayOutputStream out = new ByteArrayOutputStream(); UTF8.encode(chars, 0, chars.length, new Supplier<byte[]>() { @Override public byte[] supply() { return new byte[bufferSize]; } }, new UTF8.BytesConsumer() { @Override public void consume(byte[] buffer, int offset, int length) { out.write(buffer, offset, length); } }); Assert.assertArrayEquals(s.getBytes("utf-8"), out.toByteArray()); } }