All Downloads are FREE. Search and download functionalities are using the official Maven repository.

vip.ipav.okhttp.response.RawResponseHandler Maven / Gradle / Ivy

There is a newer version: 1.3.1
Show newest version
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) {

    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy