ChunkedInputStream 如何在内部与 Apache HttpClient 4.x 一起工作?

How does ChunkedInputStream work internally with Apache HttpClient 4.x?

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

由于文件太大,得出transfer encoding as chunkedgzip format。 Cloud env 既没有足够的磁盘 space 来将此文件存储为临时文件,也无法在内存中容纳此类文件。

主要是我有2个接口,

ResourceDownloader {
  InputStream download(AbstractChannel channel);
 }

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

第一部分:

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

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

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

还是像下面这样调用 read 时,它会从服务器获取数据块? [实际情况下,磁盘不会可用,但下面只是为了演示]

  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);
    }

第二部分:

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

谢谢, 达拉姆

HttpClient 始终流式传输请求和响应实体,除非特别指示不这样做。