public static int write(String s, byte[] bytes, int offset) { char[] chars = StringReflection.chars(s); int l = chars.length + offset; for (int i = offset; i < l; i++) { bytes[i] = (byte) chars[i - offset]; } return l; } }
public static <T> T parse(String s, JsonGeneric<T> generic) { s = s.trim(); char[] data = StringReflection.chars(s); int offset = 0; if (data.length != s.length()) offset = StringReflection.offset(s); // for java 6 return parse(data, offset, offset + s.length(), generic); }
public void write(String s, int off, int l) throws IOException { int offset = StringReflection.offset(s) + off; char[] chars = StringReflection.chars(s); write(chars, offset, l); }
public void write(String s, int off, int l) throws IOException { int offset = StringReflection.offset(s) + off; char[] chars = StringReflection.chars(s); write(chars, offset, l); }
public static int encodeWithCompression(String s, byte[] bytes, int offsetBits) { if (offsetBits % 8 != 0) return -1; int index = offsetBits >> 3; int l = s.length(); if (l <= 160) { //average compressed length for one byte int offset = StaticHttp2HuffmanTable.huffman.encode(bytes, (offsetBits + 8) >> 3, StringReflection.chars(s)); int k = 8 - offset + ((offset >> 3) << 3); if (k != 8) { bytes[offset >> 3] = (byte) (bytes[offset >> 3] | (1 << k) - 1); offset += k; } if ((offset >> 3) > 127) { //todo: shift data } bytes[index] = (byte) 128; encode((offset - offsetBits - 8) >> 3, bytes, offsetBits + 1); return offset; } else { //todo: calculate optimal size and encode } return offsetBits; }
private void parse(String auth) { char[] chars = StringReflection.chars(auth); int i = 7; int length = chars.length;
static void escape(String s, Appender sb) { char[] chars = StringReflection.chars(s); int to = s.length(); int offset = chars.length == to ? 0 : StringReflection.offset(s); int from = offset; to += from; int l = to - 1; for (int i = from; i < l; i += 2) { from = check(from, i, chars, sb); from = check(from, i + 1, chars, sb); //about 10% faster } if ((l + offset) % 2 == 0) from = check(from, l, chars, sb); if (from < to) append(chars, from, to, sb); }
try { int length = s.length(); char[] chars = StringReflection.chars(s); int i = length == chars.length ? 0 : StringReflection.offset(s); int year, month, day;
try { int length = s.length(); char[] chars = StringReflection.chars(s); int i = length == chars.length ? 0 : StringReflection.offset(s); int year, month, day;