vip.ipav.okhttp.response.RawResponseHandler Maven / Gradle / Ivy
package vip.ipav.okhttp.response;
import okhttp3.Response;
import okhttp3.ResponseBody;
import java.io.IOException;
/**
* raw 字符串结果回调
* Created by tsy on 16/8/18.
*/
public abstract class RawResponseHandler implements IResponseHandler {
@Override
public final void onSuccess(final Response response) {
ResponseBody responseBody = response.body();
String responseBodyStr = "";
try {
responseBodyStr = responseBody.string();
} catch (IOException e) {
e.printStackTrace();
onFailure(response.code(), "fail read response body");
return;
} finally {
responseBody.close();
}
final String finalResponseBodyStr = responseBodyStr;
onSuccess(response.code(), finalResponseBodyStr);
}
public abstract void onSuccess(int statusCode, String response);
@Override
public void onProgress(long currentBytes, long totalBytes) {
}
}