Compress an InputStream with gzip

前端 未结 12 1441
迷失自我
迷失自我 2020-12-29 05:28

I would like to compress an input stream in java using Gzip compression.

Let\'s say we have an input stream (1GB of data..) not compressed. I want as a result a comp

12条回答
  •  梦谈多话
    2020-12-29 06:23

    There is no DeflatingGZIPInputStream in the JRE. To deflate with the "deflate" compression format, use java.util.zip.DeflaterInputStream and java.util.zip.DeflaterOutputStream:

    public InputStream getCompressedStream(InputStream unCompressedStream) {
        return new DeflaterInputStream(unCompressedStream); 
    }
    

    You could derive a class from java.util.zip.DeflaterInputStream that deflates in GZIP format by looking at the the source of java.util.zip.GZIPOutputStream.

提交回复
热议问题