Example usage for com.squareup.okhttp Call isCanceled

List of usage examples for com.squareup.okhttp Call isCanceled

Introduction

In this page you can find the example usage for com.squareup.okhttp Call isCanceled.

Prototype

public boolean isCanceled() 

Source Link

Usage

From source file:com.facebook.imagepipeline.backends.okhttp.OkHttpNetworkFetcher.java

License:Open Source License

/**
 * Handles exceptions./*from   w  ww. j  a va 2 s .c o  m*/
 *
 * <p> OkHttp notifies callers of cancellations via an IOException. If IOException is caught
 * after request cancellation, then the exception is interpreted as successful cancellation
 * and onCancellation is called. Otherwise onFailure is called.
 */
private void handleException(final Call call, final Exception e, final Callback callback) {
    if (call.isCanceled()) {
        callback.onCancellation();
    } else {
        callback.onFailure(e);
    }
}

From source file:com.facebook.imagepipeline.backends.okhttp.OkHttpNetworkFetchProducer.java

License:Open Source License

/**
 * Handles IOExceptions.//from   w w w  .j a v  a  2  s. c o  m
 *
 * <p> OkHttp notifies callers of cancellations via an IOException. If IOException is caught
 * after request cancellation, then the exception is interpreted as successful cancellation
 * and onCancellation is called. Otherwise onFailure is called.
 */
private void handleException(final Call call, final NfpRequestState requestState, final IOException ioe) {
    if (call.isCanceled()) {
        onCancellation(requestState, null);
    } else {
        onFailure(requestState, ioe, null);
    }
}

From source file:com.hippo.nimingban.client.ac.ACEngine.java

License:Apache License

private static void throwException(Call call, String body, Exception e) throws Exception {
    if (call.isCanceled()) {
        throw new CancelledException();
    }/* w w  w  . j  a  v  a  2 s .  c  o  m*/

    if (e instanceof NMBException) {
        if (!UNKNOWN.equals(e.getMessage())) {
            throw e;
        }
    }

    if (TextUtils.isEmpty(body)) {
        return;
    }

    try {
        JSONObject jo = JSON.parseObject(body);
        if (!jo.getBoolean("success")) {
            throw new NMBException(ACSite.getInstance(), jo.getString("msg"));
        }
    } catch (Exception ee) {
        // Ignore
    }

    Document doc = Jsoup.parse(body);
    List<Element> elements = doc.getElementsByClass("error");
    if (!elements.isEmpty()) {
        throw new NMBException(ACSite.getInstance(), elements.get(0).text());
    }
}

From source file:com.hippo.nimingban.client.ConvertEngine.java

License:Apache License

public static String doConvert(Call call) throws Exception {
    try {/*from  w  w  w .ja  v a2 s  . c om*/
        Response response = call.execute();
        int code = response.code();
        if (code != 200) {
            throw new ResponseCodeException(code);
        }
        return response.body().string();
    } catch (IOException e) {
        if (call.isCanceled()) {
            throw new CancelledException();
        } else {
            throw e;
        }
    }
}

From source file:com.hippo.nimingban.client.UpdateEngine.java

License:Apache License

public static UpdateStatus doUpdate(Call call) throws Exception {
    try {//from ww w.j a  va2s. c  o m
        Response response = call.execute();
        String body = response.body().string();
        return JSON.parseObject(body, UpdateStatus.class);
    } catch (IOException e) {
        if (call.isCanceled()) {
            throw new CancelledException();
        } else {
            throw e;
        }
    }
}