Java:通过HTTP流式传输Zipfile的内容 [英] Java: Stream Contents of Zipfile via HTTP

查看:2138
本文介绍了Java:通过HTTP流式传输Zipfile的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有相当多的可流式数据(> 100MB),为了压缩,我想在http服务器上托管一个zipfile。所以这个zipfile包含一个文件。

I have quite some amount of streamable data (>100MB), which, for the sake of compression, i would like to host packed in a zipfile on an http-server. So this zipfile contains a single file.

现在java客户端可以通过http流式传输数据,即使它是打包在一个zipfile中的吗?

Now is it possible for a java-client to stream the data via http, even though it is packed in a zipfile?

根据维基百科,ZIP不是顺序的......

According to wikipedia, ZIPs are not sequentially...

http://en.wikipedia.org/wiki/ZIP_(file_format)#Structure

如果仍然可能以某种方式,那么如何?

If this is still possible somehow, then how?

编辑:关于gzip:正如我所说,我使用的是自定义java客户端(不是webbrowser) )是java http实现中的gzip吗?

edit: about gzip: as i said, i use a custom java client (not a webbrowser) is gzip available in the java http implementation?

推荐答案

Java支持 gzip 格式为 GZipInputStream (解压缩)和 GZipOutputStream (压缩)。 zip gzip 都在内部使用相同的压缩格式,主要区别在于元数据: zip 在文件的末尾, gzip 在开头(和 gzip 只支持一个封闭的文件。)

Java supports the gzip format with the GZipInputStream (decompressing) and GZipOutputStream (compressing). Both zip and gzip use the same compressing format internally, the main difference is in the metadata: zip has it at the end of the file, gzip at the beginning (and gzip only supports one enclosed file easily).

对于流式传输一个大文件,使用 gzip 将是更好的事情 - 甚至更多,因为你不需要访问元数据。

For your of streaming one big file, using gzip will be the better thing to do - even more as you don't need access to the metadata.

我不确定HTTPConnection是否发送接受 - 编码:gzip 然后如果服务器通过 Content-Encoding:gzip 提供内容,则会自动处理内容,但你肯定可以手动执行服务器只是发送 .gz 文件(即 Content-Encoding:identity )。

I'm not sure if the HTTPConnection sends Accept-Encoding: gzip and then handles inflating the content automatically if the server delivers it with Content-Encoding: gzip, but you surely can do it manually if the server simply sends a the .gz file as such (i.e. with Content-Encoding: identity).

(顺便说一句,确保从流中读取缓冲区不太小,因为每个deflate调用都会有本机调用开销,因为Java的GZipInputStream使用nativ e zlib 实施。)

(By the way, make sure to read from the stream with not too small buffers, as each deflate call will have a native call overhead, since Java's GZipInputStream uses the native zlib implementation.)

这篇关于Java:通过HTTP流式传输Zipfile的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆