@SuppressWarnings("unchecked") public static final <T> T parseObject(byte[] input, int off, int len, CharsetDecoder charsetDecoder, Type clazz, Feature... features) { charsetDecoder.reset(); int scaleLength = (int) (len * (double) charsetDecoder.maxCharsPerByte()); char[] chars = ThreadLocalCache.getChars(scaleLength); ByteBuffer byteBuf = ByteBuffer.wrap(input, off, len); CharBuffer charByte = CharBuffer.wrap(chars); IOUtils.decode(charsetDecoder, byteBuf, charByte); int position = charByte.position(); return (T) parseObject(chars, position, clazz, features); }
private <T> T toParseObject(byte[] input, int off, int len, CharsetDecoder charsetDecoder, Type clazz) { charsetDecoder.reset(); int scaleLength = (int) (len * (double) charsetDecoder.maxCharsPerByte()); char[] chars = ThreadLocalCache.getChars(scaleLength); ByteBuffer byteBuf = ByteBuffer.wrap(input, off, len); CharBuffer charByte = CharBuffer.wrap(chars); IOUtils.decode(charsetDecoder, byteBuf, charByte); int position = charByte.position(); if (chars.length == 0) { return null; } DefaultJSONParser parser = new DefaultJSONParser(chars, position, parseConfig, DEFAULT_PARSER_FEATURE); T value = parser.parseObject(clazz); parser.handleResovleTask(value); parser.close(); return value; }
public byte[] encode(char[] chars, int off, int len) { if (len == 0) { return new byte[0]; } this.encoder.reset(); return encode(chars, off, len, ThreadLocalCache.getBytes(scale(len, this.encoder.maxBytesPerChar()))); }
public static final Object parse(byte[] input, int off, int len, CharsetDecoder charsetDecoder, int features) { charsetDecoder.reset(); char[] chars = ThreadLocalCache.getChars((int) (((double) len) * ((double) charsetDecoder.maxCharsPerByte()))); ByteBuffer byteBuf = ByteBuffer.wrap(input, off, len); CharBuffer charBuf = CharBuffer.wrap(chars); IOUtils.decode(charsetDecoder, byteBuf, charBuf); DefaultJSONParser parser = new DefaultJSONParser(chars, charBuf.position(), ParserConfig.getGlobalInstance(), features); Object value = parser.parse(); parser.handleResovleTask(value); parser.close(); return value; }
public static final <T> T parseObject(byte[] input, int off, int len, CharsetDecoder charsetDecoder, Type clazz, Feature... features) { charsetDecoder.reset(); char[] chars = ThreadLocalCache.getChars((int) (((double) len) * ((double) charsetDecoder.maxCharsPerByte()))); ByteBuffer byteBuf = ByteBuffer.wrap(input, off, len); CharBuffer charByte = CharBuffer.wrap(chars); IOUtils.decode(charsetDecoder, byteBuf, charByte); return parseObject(chars, charByte.position(), clazz, features); }
@SuppressWarnings("unchecked") public <T> T getObjectFromBytes(byte[] input, Class<T> clazz) { if (input == null) { return null; } else if (String.class.equals(clazz)) { return (T) new String(input, Charset.forName("UTF8")); } return toParseObject(input, 0, input.length, ThreadLocalCache.getUTF8Decoder(), clazz); }
public void test_threadCache() throws Exception { ThreadLocalCache.getBytes(10); }
public static final Object parse(byte[] input, Feature... features) { return parse(input, 0, input.length, ThreadLocalCache.getUTF8Decoder(), features); }
public static final <T> T parseObject(byte[] input, Type clazz, Feature... features) { return parseObject(input, 0, input.length, ThreadLocalCache.getUTF8Decoder(), clazz, features); }
public static final Object parse(byte[] input, int off, int len, CharsetDecoder charsetDecoder, int features) { charsetDecoder.reset(); int scaleLength = (int) (len * (double) charsetDecoder.maxCharsPerByte()); char[] chars = ThreadLocalCache.getChars(scaleLength); ByteBuffer byteBuf = ByteBuffer.wrap(input, off, len); CharBuffer charBuf = CharBuffer.wrap(chars); IOUtils.decode(charsetDecoder, byteBuf, charBuf); int position = charBuf.position(); DefaultJSONParser parser = new DefaultJSONParser(chars, position, ParserConfig.getGlobalInstance(), features); Object value = parser.parse(); parser.handleResovleTask(value); parser.close(); return value; }
@SuppressWarnings("unchecked") public static final <T> T parseObject(byte[] input, Type clazz, Feature... features) { return (T) parseObject(input, 0, input.length, ThreadLocalCache.getUTF8Decoder(), clazz, features); }
public static final Object parse(byte[] input, int off, int len, CharsetDecoder charsetDecoder, int features) { charsetDecoder.reset(); int scaleLength = (int) (len * (double) charsetDecoder.maxCharsPerByte()); char[] chars = ThreadLocalCache.getChars(scaleLength); ByteBuffer byteBuf = ByteBuffer.wrap(input, off, len); CharBuffer charBuf = CharBuffer.wrap(chars); IOUtils.decode(charsetDecoder, byteBuf, charBuf); int position = charBuf.position(); DefaultJSONParser parser = new DefaultJSONParser(chars, position, ParserConfig.getGlobalInstance(), features); Object value = parser.parse(); handleResovleTask(parser, value); parser.close(); return value; }
public byte[] encode(char[] chars, int off, int len) { if (len == 0) { return new byte[0]; } encoder.reset(); int bytesLength = scale(len, encoder.maxBytesPerChar()); byte[] bytes = ThreadLocalCache.getBytes(bytesLength); return encode(chars, off, len, bytes); }