當前位置: 首頁>>代碼示例>>Java>>正文


Java ResponseBody.byteStream方法代碼示例

本文整理匯總了Java中com.squareup.okhttp.ResponseBody.byteStream方法的典型用法代碼示例。如果您正苦於以下問題:Java ResponseBody.byteStream方法的具體用法?Java ResponseBody.byteStream怎麽用?Java ResponseBody.byteStream使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.squareup.okhttp.ResponseBody的用法示例。


在下文中一共展示了ResponseBody.byteStream方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getStreamFromNetwork

import com.squareup.okhttp.ResponseBody; //導入方法依賴的package包/類
@Override
protected InputStream getStreamFromNetwork(String imageUri, Object extra) throws IOException {
	Request request = new Request.Builder().url(imageUri).build();
	ResponseBody responseBody = client.newCall(request).execute().body();
	InputStream inputStream = responseBody.byteStream();
	int contentLength = (int) responseBody.contentLength();
	return new ContentLengthInputStream(inputStream, contentLength);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:9,代碼來源:OkHttpImageDownloader.java

示例2: downloadFile

import com.squareup.okhttp.ResponseBody; //導入方法依賴的package包/類
private boolean downloadFile(@NonNull String url, @NonNull File targetFile) {
    LOGD(TAG, "Downloading \"" + url + "\" into \"" + targetFile + "\"...");
    Request request = new Request.Builder().url(url).tag(OKHTTP_TAG).build();
    Response response;
    try {
        response = mOkHttpClient.newCall(request).execute();
        if (!response.isSuccessful()) {
            return false;
        }
        final ResponseBody body = response.body();
        final InputStream inputStream = body.byteStream();
        final OutputStream outputStream = new FileOutputStream(targetFile);
        byte[] buffer = new byte[BUFFER_SIZE];
        int len;
        while ((len = inputStream.read(buffer)) != -1) {
            outputStream.write(buffer, 0, len);
            mDownloaded += len;
            publishProgress((int) (mDownloaded * 100 / mSelectedMap.getMapSize()));
        }
        inputStream.close();
        outputStream.close();
    } catch (IOException e) {
        LOGE(TAG, "Cannot download map.", e);
        return false;
    }
    LOGD(TAG, "Downloaded.");
    return true;
}
 
開發者ID:yuviii,項目名稱:OfflineMap,代碼行數:29,代碼來源:MapDownloaderLoader.java

示例3: fetchStream

import com.squareup.okhttp.ResponseBody; //導入方法依賴的package包/類
protected InputStream fetchStream(Uri url, int staleness) {
    ensureCache();
    ResponseBody body = fetchFromNetwork(url, staleness);
    if (body != null) {
        try {
            return body.byteStream();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    return null;
}
 
開發者ID:nextux,項目名稱:sbs-android-tv,代碼行數:13,代碼來源:HttpApiBase.java

示例4: intercept

import com.squareup.okhttp.ResponseBody; //導入方法依賴的package包/類
@Override
public Response intercept(Chain chain) throws IOException {
  String requestId = String.valueOf(mNextRequestId.getAndIncrement());

  Request request = chain.request();

  RequestBodyHelper requestBodyHelper = null;
  if (mEventReporter.isEnabled()) {
    requestBodyHelper = new RequestBodyHelper(mEventReporter, requestId);
    OkHttpInspectorRequest inspectorRequest =
        new OkHttpInspectorRequest(requestId, request, requestBodyHelper);
    mEventReporter.requestWillBeSent(inspectorRequest);
  }

  Response response;
  try {
    response = chain.proceed(request);
  } catch (IOException e) {
    if (mEventReporter.isEnabled()) {
      mEventReporter.httpExchangeFailed(requestId, e.toString());
    }
    throw e;
  }

  if (mEventReporter.isEnabled()) {
    if (requestBodyHelper != null && requestBodyHelper.hasBody()) {
      requestBodyHelper.reportDataSent();
    }

    Connection connection = chain.connection();
    mEventReporter.responseHeadersReceived(
        new OkHttpInspectorResponse(
            requestId,
            request,
            response,
            connection));

    ResponseBody body = response.body();
    MediaType contentType = null;
    InputStream responseStream = null;
    if (body != null) {
      contentType = body.contentType();
      responseStream = body.byteStream();
    }

    responseStream = mEventReporter.interpretResponseStream(
        requestId,
        contentType != null ? contentType.toString() : null,
        response.header("Content-Encoding"),
        responseStream,
        new DefaultResponseHandler(mEventReporter, requestId));
    if (responseStream != null) {
      response = response.newBuilder()
          .body(new ForwardingResponseBody(body, responseStream))
          .build();
    }
  }

  return response;
}
 
開發者ID:Laisly,項目名稱:weex,代碼行數:61,代碼來源:OkHttpInterceptor.java


注:本文中的com.squareup.okhttp.ResponseBody.byteStream方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。