public static String read(byte[] buffer, int bufferLength, byte[] bytes, int offset, int length) { char[] data = new char[bufferLength + length]; int h = 0; int k; for (int i = 0; i < bufferLength; i++) { data[i] = (char) (k = (buffer[i] & 0xff)); h = 31 * h + k; } for (int i = 0; i < length; i++) { data[i + bufferLength] = (char) (k = (bytes[offset + i] & 0xff)); h = 31 * h + k; } return StringReflection.createString(data, h); }
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 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;
public static String read(byte[] bytes, int offset, int length, int hash) { // return read(bytes, offset, length); if (length <= 0) return new String(); char[] data = new char[length]; for (int i = 0; i < length; i++) { data[i] = (char) (bytes[offset + i] & 0xff); } return StringReflection.createString(data, hash); }
public static String read(byte[] bytes, int offset, int length) { if (length <= 0) return new String(); int h = 0; int k; char[] data = new char[length]; for (int i = 0; i < length; i++) { data[i] = (char) (k = (bytes[offset + i] & 0xff)); h = 31 * h + k; } return StringReflection.createString(data, h); }
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); }
public static String format(Date date, TimeZone timeZone) { return StringReflection.createString(formatToChars(date, timeZone)); }
public static String format(Date date, TimeZone timeZone) { return StringReflection.createString(formatToChars(date, timeZone)); }