当前位置: 首页>>代码示例>>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;未经允许,请勿转载。