Java 类com.alibaba.fastjson.util.ThreadLocalCache 实例源码

项目:uavstack    文件:JSON.java   
@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);
}
项目:navi    文件:AlibabaJsonSerializer.java   
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;
}
项目:itmarry    文件:JSON.java   
@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);
}
项目:android_http_demo    文件:JSON.java   
@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);
}
项目:AndroidNio    文件:JSON.java   
@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);
}
项目:boohee_v5.6    文件:SerialWriterStringEncoder.java   
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())));
}
项目:boohee_v5.6    文件:JSON.java   
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;
}
项目:boohee_v5.6    文件:JSON.java   
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);
}
项目:navi    文件:AlibabaJsonSerializer.java   
@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);
}
项目:GitHub    文件:ThreadLocalCacheTest.java   
public void test_threadCache() throws Exception {
    ThreadLocalCache.getBytes(10);
}
项目:boohee_v5.6    文件:JSON.java   
public static final Object parse(byte[] input, Feature... features) {
    return parse(input, 0, input.length, ThreadLocalCache.getUTF8Decoder(), features);
}
项目:boohee_v5.6    文件:JSON.java   
public static final <T> T parseObject(byte[] input, Type clazz, Feature... features) {
    return parseObject(input, 0, input.length, ThreadLocalCache.getUTF8Decoder(), clazz, features);
}
项目:uavstack    文件:JSON.java   
public static final Object parse(byte[] input, Feature... features) {
    return parse(input, 0, input.length, ThreadLocalCache.getUTF8Decoder(), features);
}
项目:uavstack    文件:JSON.java   
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;
}
项目:uavstack    文件:JSON.java   
@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);
}
项目:itmarry    文件:JSON.java   
public static final Object parse(byte[] input, Feature... features) {
    return parse(input, 0, input.length, ThreadLocalCache.getUTF8Decoder(), features);
}
项目:itmarry    文件:JSON.java   
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;
}
项目:itmarry    文件:JSON.java   
@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);
}
项目:android_http_demo    文件:JSON.java   
public static final Object parse(byte[] input, Feature... features) {
    return parse(input, 0, input.length, ThreadLocalCache.getUTF8Decoder(), features);
}
项目:android_http_demo    文件:JSON.java   
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;
}
项目:android_http_demo    文件:JSON.java   
@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);
}
项目:AndroidNio    文件:JSON.java   
public static final Object parse(byte[] input, Feature... features) {
    return parse(input, 0, input.length, ThreadLocalCache.getUTF8Decoder(), features);
}
项目:AndroidNio    文件:JSON.java   
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;
}
项目:AndroidNio    文件:JSON.java   
@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);
}
项目:uavstack    文件:SerialWriterStringEncoder.java   
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);
}
项目:itmarry    文件:SerialWriterStringEncoder.java   
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);
}
项目:android_http_demo    文件:SerialWriterStringEncoder.java   
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);
}
项目:AndroidNio    文件:SerialWriterStringEncoder.java   
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);
}