- 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 int decode(byte[] bytes, int offset, int length, char[] chars) { return decode(bytes, offset, length, chars, 0); }
public static int decode(byte[] bytes, int offset, int length, char[] chars) { return decode(bytes, offset, length, chars, 0); }
for (int i = 0; i <= 0x7F; i++) { bytes[0] = (byte) i; int r = UTF8.decode(bytes, 0, bytes.length, chars); Assert.assertEquals(new String(bytes, charset), new String(chars, 0, r)); for (int j = 0; j < 256; j++) { bytes[1] = (byte) (j & 0x7f | 0x80); int r = UTF8.decode(bytes, 0, bytes.length, chars); Assert.assertEquals(i + " " + j, new String(bytes, charset), new String(chars, 0, r)); for (int k = 0; k < 64; k++) { bytes[2] = (byte) (k & 0x7f | 0x80); int r = UTF8.decode(bytes, 0, bytes.length, chars); String expected = new String(bytes, charset); if (expected.charAt(0) >= '\uD800' && expected.charAt(0) <= '\uDFFF') for (int m = 0; m < 64; m++) { bytes[3] = (byte) (m & 0x7f | 0x80); int r = UTF8.decode(bytes, 0, bytes.length, chars); if (r == 1 && chars[0] == '�') { char[] c = new String(bytes, charset).toCharArray();
@Test public void decode_continuous_1() throws UnsupportedEncodingException { String s = "€"; char[] chars = new char[1]; byte[] bytes = s.getBytes("utf-8"); Assert.assertEquals(3, bytes.length); int read; UTF8.DecodeOffsets offsets = new UTF8.DecodeOffsets(); read = 1; offsets = UTF8.decode(bytes, read, chars, offsets); Assert.assertEquals(0, offsets.bytesOffset); Assert.assertEquals(0, offsets.charsOffset); read++; offsets = UTF8.decode(bytes, read, chars, offsets); Assert.assertEquals(0, offsets.bytesOffset); Assert.assertEquals(0, offsets.charsOffset); read++; offsets = UTF8.decode(bytes, read, chars, offsets); Assert.assertEquals(3, offsets.bytesOffset); Assert.assertEquals(1, offsets.charsOffset); Assert.assertEquals(s.charAt(0), chars[0]); }
@Test public void decode_continuous_3() throws UnsupportedEncodingException { String s = "€"; char[] chars = new char[1]; byte[] bytes = s.getBytes("utf-8"); Assert.assertEquals(3, bytes.length); UTF8.DecodeContext context = new UTF8.DecodeContext(); context = UTF8.decode(bytes, 0, 1, chars, context); Assert.assertEquals(0, context.charsOffset); Assert.assertEquals(1, context.length); Assert.assertEquals(bytes[0], context.buffer[0]); context = UTF8.decode(bytes, 1, 1, chars, context); Assert.assertEquals(0, context.charsOffset); Assert.assertEquals(2, context.length); Assert.assertEquals(bytes[0], context.buffer[0]); Assert.assertEquals(bytes[1], context.buffer[1]); context = UTF8.decode(bytes, 2, 1, chars, context); Assert.assertEquals(1, context.charsOffset); Assert.assertEquals(0, context.length); Assert.assertEquals(s.charAt(0), chars[0]); }
context.buffer[cl++] = bytes[offset++]; context.length = 0; if (decode(context.buffer, 0, cl, chars, context).charsOffset == i) { // 2 bytes if (offset < to) { context.buffer[cl++] = bytes[offset++]; context.length = 0; if (decode(context.buffer, 0, cl, chars, context).charsOffset == i) {// 3 bytes if (offset < to) { context.buffer[cl++] = bytes[offset++]; context.length = 0; i = decode(context.buffer, 0, cl, chars, context).charsOffset; // 4 bytes } else { context.length = cl;
@Test public void decode_continuous_2() throws UnsupportedEncodingException { String s = "€"; char[] chars = new char[1]; byte[] bytes = s.getBytes("utf-8"); Assert.assertEquals(3, bytes.length); UTF8.DecodeContext context = new UTF8.DecodeContext(); context = UTF8.decode(bytes, 0, 2, chars, context); Assert.assertEquals(0, context.charsOffset); Assert.assertEquals(2, context.length); Assert.assertEquals(bytes[0], context.buffer[0]); Assert.assertEquals(bytes[1], context.buffer[1]); context = UTF8.decode(bytes, 2, 1, chars, context); Assert.assertEquals(1, context.charsOffset); Assert.assertEquals(0, context.length); Assert.assertEquals(s.charAt(0), chars[0]); }
context.buffer[cl++] = bytes[offset++]; context.length = 0; if (decode(context.buffer, 0, cl, chars, context).charsOffset == i) { // 2 bytes if (offset < to) { context.buffer[cl++] = bytes[offset++]; context.length = 0; if (decode(context.buffer, 0, cl, chars, context).charsOffset == i) {// 3 bytes if (offset < to) { context.buffer[cl++] = bytes[offset++]; context.length = 0; i = decode(context.buffer, 0, cl, chars, context).charsOffset; // 4 bytes } else { context.length = cl;
context = UTF8.decode(bytes, 0, 1, chars, context); Assert.assertEquals(0, context.charsOffset); Assert.assertEquals(1, context.length); Assert.assertEquals(bytes[0], context.buffer[0]); context = UTF8.decode(bytes, 1, 1, chars, context); Assert.assertEquals(0, context.charsOffset); Assert.assertEquals(2, context.length); context = UTF8.decode(bytes, 2, 1, chars, context); Assert.assertEquals(0, context.charsOffset); Assert.assertEquals(3, context.length); context = UTF8.decode(bytes, 3, 1, chars, context); Assert.assertEquals(2, context.charsOffset); Assert.assertEquals(0, context.length); context = UTF8.decode(bytes, 0, 1, chars, context); Assert.assertEquals(0, context.charsOffset); Assert.assertEquals(1, context.length); Assert.assertEquals(bytes[0], context.buffer[0]); context = UTF8.decode(bytes, 1, 3, chars, context); Assert.assertEquals(2, context.charsOffset); Assert.assertEquals(0, context.length); context = UTF8.decode(bytes, 0, 2, chars, context); Assert.assertEquals(0, context.charsOffset); Assert.assertEquals(2, context.length);