Tomcat:WebService 响应为 zip 存档而不是文件
我希望网络服务以 zip 文件形式做出响应。
一般来说,没有什么难做的事情。但我想知道一件事: 即使文件很大(100Mb - 500Mb),我可以压缩文件而不将其保存到硬盘吗?
现在我正在使用这个不错的技巧。我想通过压缩功能来扩展它,而不在文件系统上创建新文件。
public class TempFileInputStream extends FileInputStream {
private File file;
public TempFileInputStream(File file) throws FileNotFoundException {
super(file); // TO WANT: to pass here already zipped stream
this.file = file;
}
@Override
public void close() throws IOException {
super.close();
if (!file.delete()) {
// baad
} else {
// good
}
}
}
如果可以,那么更好/最佳的方法是什么?
感谢您的帮助!
I want web service to make response as a zip file.
Generally there is nothing hard to do. But there is one thing I want to know:
Can I zip file without saving it to the hard disk, even if it's very large (100Mb - 500Mb)?
Now I'm using this nice hack. And i want to extend it with ziping functionality without creating new files on the file system.
public class TempFileInputStream extends FileInputStream {
private File file;
public TempFileInputStream(File file) throws FileNotFoundException {
super(file); // TO WANT: to pass here already zipped stream
this.file = file;
}
@Override
public void close() throws IOException {
super.close();
if (!file.delete()) {
// baad
} else {
// good
}
}
}
If I can, then what is the better/optimal way to do it ?
Thanks for any help !
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看看这个:
http:// /download.oracle.com/javase/1.4.2/docs/api/java/util/zip/ZipOutputStream.html
希望有所帮助...
take a look at this:
http://download.oracle.com/javase/1.4.2/docs/api/java/util/zip/ZipOutputStream.html
hope that helps...