Esempio n. 1
0
  private void handleResponse(HttpUriRequest request, HttpResponse response) {
    StatusLine status = response.getStatusLine();
    if (status.getStatusCode() >= 300) {
      String errorMsg = "response status error code:" + status.getStatusCode();
      if (status.getStatusCode() == 416 && isResume) {
        errorMsg += " \n maybe you have download complete.";
      }
      publishProgress(
          UPDATE_FAILURE,
          new HttpResponseException(status.getStatusCode(), status.getReasonPhrase()),
          status.getStatusCode(),
          errorMsg);
    } else {
      try {

        // 检查 服务器返回状态
        if (mCheckResponse != null) {
          //
          if (mCheckResponse.checkResponse(request, response)) return;
        }

        // 解析请求体
        HttpEntity entity = response.getEntity();
        Object responseBody = null;
        if (entity != null) {
          time = SystemClock.uptimeMillis();
          if (targetUrl != null) {
            responseBody = mFileEntityHandler.handleEntity(entity, this, targetUrl, isResume);
          } else {
            responseBody = mStrEntityHandler.handleEntity(entity, this, charset);
          }
        }
        publishProgress(UPDATE_SUCCESS, responseBody, request, response);
      } catch (IOException e) {
        publishProgress(UPDATE_FAILURE, e, 0, e.getMessage());
      } catch (SeverRequestException e) {
        publishProgress(UPDATE_FAILURE, e, 0, e.getMessage());
      }
    }
  }
Esempio n. 2
0
 /** @param stop 停止下载任务 */
 public void stop() {
   mFileEntityHandler.setStop(true);
 }
Esempio n. 3
0
 public boolean isStop() {
   return mFileEntityHandler.isStop();
 }