Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
/**
*
*/
@FunctionalInterface
public interface TDHttpRequestHandler<Result>
{
static class ResponseContext
Expand Down
33 changes: 5 additions & 28 deletions src/main/java/com/treasuredata/client/TDHttpRequestHandlers.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.treasuredata.client;

import com.google.common.base.Function;
import okhttp3.Response;
import okhttp3.ResponseBody;

import java.io.InputStream;
Expand All @@ -15,37 +14,15 @@ private TDHttpRequestHandlers()
{
}

public static final TDHttpRequestHandler<String> stringContentHandler = new TDHttpRequestHandler<String>()
{
@Override
public String onSuccess(Response response)
throws Exception
{
return response.body().string();
}
};
public static final TDHttpRequestHandler<String> stringContentHandler = response -> response.body().string();

public static final TDHttpRequestHandler<byte[]> byteArrayContentHandler = new TDHttpRequestHandler<byte[]>()
{
@Override
public byte[] onSuccess(Response response)
throws Exception
{
return response.body().bytes();
}
};
public static final TDHttpRequestHandler<byte[]> byteArrayContentHandler = response -> response.body().bytes();

public static final <Result> TDHttpRequestHandler<Result> newByteStreamHandler(final Function<InputStream, Result> handler)
{
return new TDHttpRequestHandler<Result>()
{
@Override
public Result onSuccess(Response response)
throws Exception
{
try (ResponseBody body = response.body()) {
return handler.apply(body.byteStream());
}
return response -> {
try (ResponseBody body = response.body()) {
return handler.apply(body.byteStream());
}
};
}
Expand Down