com.treasuredata.client.TDHttpRequestHandlers Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of td-client Show documentation
Show all versions of td-client Show documentation
Treasure Data Client for Java.
package com.treasuredata.client;
import com.google.common.base.Function;
import okhttp3.Response;
import okhttp3.ResponseBody;
import java.io.InputStream;
/**
* Request handler implementations
*/
public class TDHttpRequestHandlers
{
private TDHttpRequestHandlers()
{
}
public static final TDHttpRequestHandler stringContentHandler = new TDHttpRequestHandler()
{
@Override
public String onSuccess(Response response)
throws Exception
{
return response.body().string();
}
};
public static final TDHttpRequestHandler byteArrayContentHandler = new TDHttpRequestHandler()
{
@Override
public byte[] onSuccess(Response response)
throws Exception
{
return response.body().bytes();
}
};
public static final TDHttpRequestHandler newByteStreamHandler(final Function handler)
{
return new TDHttpRequestHandler()
{
@Override
public Result onSuccess(Response response)
throws Exception
{
try (ResponseBody body = response.body()) {
return handler.apply(body.byteStream());
}
}
};
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy