Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package com.koushikdutta.ion.gson;
 
Created by koush on 5/27/13.
public abstract class GsonParser<T extends JsonElementimplements AsyncParser<T> {
    Class<? extends JsonElementclazz;
    public GsonParser(Class<? extends T> clazz) {
        this. = clazz;
    }
    public GsonParser(Class<? extends T> clazzCharset charset) {
        this(clazz);
        this. = charset;
    }
    @Override
    public Future<T> parse(DataEmitter emitter) {
        final String charset = emitter.charset();
        return new ByteBufferListParser().parse(emitter)
        .then(new TransformFuture<T, ByteBufferList>() {
            @Override
            protected void transform(ByteBufferList resultthrows Exception {
                JsonParser parser = new JsonParser();
                ByteBufferListInputStream bis = new ByteBufferListInputStream(result);
                InputStreamReader isr;
                if ( != null)
                    isr = new InputStreamReader(bis);
                else if (charset != null)
                    isr = new InputStreamReader(bischarset);
                else
                    isr = new InputStreamReader(bis);
                JsonElement parsed = parser.parse(new JsonReader(isr));
                if (parsed.isJsonNull() || parsed.isJsonPrimitive())
                    throw new JsonParseException("unable to parse json");
                if (!.isInstance(parsed))
                    throw new ClassCastException(parsed.getClass().getCanonicalName() + " can not be casted to " + .getCanonicalName());
                setComplete(null, (T)parsed);
            }
        });
    }
    @Override
    public void write(DataSink sink, T valueCompletedCallback completed) {
        new StringParser().write(sinkvalue.toString(), completed);
    }
    @Override
    public Type getType() {
        return ;
    }
New to GrepCode? Check out our FAQ X