/** Convert UTF8 bytes into a String */ public static String UTF8toUTF16(byte[] utf8, int offset, int len) { char[] out = new char[len]; int n = UTF8toUTF16(utf8, offset, len, out, 0); return new String(out,0,n); }
/** Convert UTF8 bytes into a String */ public static String UTF8toUTF16(byte[] utf8, int offset, int len) { char[] out = new char[len]; int n = UTF8toUTF16(utf8, offset, len, out, 0); return new String(out,0,n); }
public String get(StringBytes b) { String result = cache.get(b); if (result == null) { //make a copy because the buffer received may be changed later by the caller StringBytes copy = new StringBytes(Arrays.copyOfRange(b.bytes, b.offset, b.offset + b.length), 0, b.length); CharArr arr = new CharArr(); ByteUtils.UTF8toUTF16(b.bytes, b.offset, b.length, arr); result = arr.toString(); cache.put(copy, result); } return result; } }
public String get(StringBytes b) { String result = cache.get(b); if (result == null) { //make a copy because the buffer received may be changed later by the caller StringBytes copy = new StringBytes(Arrays.copyOfRange(b.bytes, b.offset, b.offset + b.length), 0, b.length); CharArr arr = new CharArr(); ByteUtils.UTF8toUTF16(b.bytes, b.offset, b.length, arr); result = arr.toString(); cache.put(copy, result); } return result; } }
public static Object fromJSON(byte[] utf8) { // convert directly from bytes to chars // and parse directly from that instead of going through // intermediate strings or readers CharArr chars = new CharArr(); ByteUtils.UTF8toUTF16(utf8, 0, utf8.length, chars); JSONParser parser = new JSONParser(chars.getArray(), chars.getStart(), chars.length()); try { return ObjectBuilder.getVal(parser); } catch (IOException e) { throw new RuntimeException(e); // should never happen w/o using real IO } }
/** Convert UTF8 bytes into UTF16 characters. */ public static void UTF8toUTF16(byte[] utf8, int offset, int len, CharArr out) { // TODO: do in chunks if the input is large out.reserve(len); int n = UTF8toUTF16(utf8, offset, len, out.getArray(), out.getEnd()); out.setEnd(out.getEnd() + n); }
/** Convert UTF8 bytes into UTF16 characters. */ public static void UTF8toUTF16(byte[] utf8, int offset, int len, CharArr out) { // TODO: do in chunks if the input is large out.reserve(len); int n = UTF8toUTF16(utf8, offset, len, out.getArray(), out.getEnd()); out.setEnd(out.getEnd() + n); }
public static Object fromJSON(byte[] utf8) { // convert directly from bytes to chars // and parse directly from that instead of going through // intermediate strings or readers CharArr chars = new CharArr(); ByteUtils.UTF8toUTF16(utf8, 0, utf8.length, chars); JSONParser parser = new JSONParser(chars.getArray(), chars.getStart(), chars.length()); parser.setFlags(parser.getFlags() | JSONParser.ALLOW_MISSING_COLON_COMMA_BEFORE_OBJECT | JSONParser.OPTIONAL_OUTER_BRACES); try { return STANDARDOBJBUILDER.apply(parser).getVal(parser); } catch (IOException e) { throw new RuntimeException(e); // should never happen w/o using real IO } }
public String readStr(DataInputInputStream dis, StringCache stringCache) throws IOException { int sz = readSize(dis); if (bytes == null || bytes.length < sz) bytes = new byte[sz]; dis.readFully(bytes, 0, sz); if (stringCache != null) { return stringCache.get(bytesRef.reset(bytes, 0, sz)); } else { arr.reset(); ByteUtils.UTF8toUTF16(bytes, 0, sz, arr); return arr.toString(); } }
public String readStr(DataInputInputStream dis, StringCache stringCache) throws IOException { int sz = readSize(dis); if (bytes == null || bytes.length < sz) bytes = new byte[sz]; dis.readFully(bytes, 0, sz); if (stringCache != null) { return stringCache.get(bytesRef.reset(bytes, 0, sz)); } else { arr.reset(); ByteUtils.UTF8toUTF16(bytes, 0, sz, arr); return arr.toString(); } }