Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package com.koushikdutta.ion.gson;
 
 import  com.google.gson.Gson;
 import  com.google.gson.reflect.TypeToken;
Created by koush on 6/5/13.
public class PojoBody<T> implements AsyncHttpRequestBody<T> {
    T pojo;
    byte[] bodyBytes;
    Type type;
    Gson gson;
    public PojoBody(Gson gson, T pojo, TypeToken<T> token) {
        this. = pojo;
        if (token != null)
            this. = token.getType();
        this. = gson;
    }
    byte[] getBodyBytes() {
        if ( != null)
            return ;
        ByteArrayOutputStream bout = new ByteArrayOutputStream();
        OutputStreamWriter out = new OutputStreamWriter(bout);
        if ( == null)
            .toJson(out);
        else
            .toJson(out);
        try {
            out.flush();
            bout.flush();
        }
        catch (Exception e) {
        }
         = bout.toByteArray();
        return ;
    }
    @Override
    public void write(AsyncHttpRequest requestDataSink sinkfinal CompletedCallback completed) {
        Util.writeAll(sinkgetBodyBytes(), completed);
    }
    @Override
    public void parse(DataEmitter emitterCompletedCallback completed) {
    }
    @Override
    public String getContentType() {
        return ;
    }
    @Override
    public boolean readFullyOnRequest() {
        return true;
    }
    @Override
    public int length() {
        return getBodyBytes().length;
    }
    @Override
    public T get() {
        return ;
    }
    public static final String CONTENT_TYPE = "application/json";
New to GrepCode? Check out our FAQ X