开发者

Tomcat: WebService response as zip archive instead of file

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 !


take a look at this:

http://download.oracle.com/javase/1.4.2/docs/api/java/util/zip/ZipOutputStream.html

hope that helps...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜