【问题标题】:How does ChunkedInputStream work internally with Apache HttpClient 4.x?ChunkedInputStream 如何在内部与 Apache HttpClient 4.x 一起工作?
【发布时间】:2017-01-11 21:50:08
【问题描述】:

我对 Apache HC API 有点陌生。我正在尝试从服务器 (10 GB) on cloud environment 下载大文件,然后我必须上传到 Amazon S3。

由于文件太大,它会出现transfer encoding as chunkedgzip format。 Cloud env 既没有足够的磁盘空间将该文件存储为临时文件,也无法在内存中容纳该文件。

主要是我有2个接口,

ResourceDownloader {
  InputStream download(AbstractChannel channel);
 }

ResourceUploader{
   void upload(AbstractChannel channel, InputStream inputStream);
}

第 1 部分:

在使用 Apache Httpclient 库时,我看到返回具有以下结构的 http 响应,

ResponseEntityProxy contains >> {
 - BasicHttpEntity [WrappedEntity]
 - content as ChunkeInputStream
}

那么这个响应是否意味着在 client.execute(getMethod) 调用完成后整个 10GB 将在客户端的内存字节缓冲区中可用?

或者是不是就像我调用如下所示的读取调用,它会从服务器获取块? [在实际情况下,磁盘将不可用,但以下仅用于演示]

  try {
        FileOutputStream fos = (FileOutputStream) outputStream;

        if(inputStream instanceof GZIPInputStream) {
            byte[] buffer = new byte[1024];
            int len;
            while((len = inputStream.read(buffer)) != -1){
                fos.write(buffer, 0, len);
            }
            //close resources
            fos.close();
            inputStream.close();
        }

    } catch (IOException e) {
        logger.error("Exception occurred while processing file on disk", e);
    }

第 2 部分:

如果我有可用的内容长度或完整文件,我知道分段上传,但在分块输入流的情况下,我们应该如何将其上传到 Amazon S3?

谢谢, 达兰

【问题讨论】:

    标签: amazon-s3 apache-httpclient-4.x apache-httpcomponents spring-restcontroller spring-rest


    【解决方案1】:

    HttpClient 始终流式传输请求和响应实体,除非另有明确指示。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多