Compress an InputStream with gzip

前端 未结 12 1364
迷失自我
迷失自我 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:18

    You can use EasyStream.

    try(final InputStreamFromOutputStream isOs = new InputStreamFromOutputStream() {
        @Override
        protected void produce(final OutputStream dataSink) throws Exception {
            InputStream in = new GZIPInputStream(unCompressedStream);
            IOUtils.copy(in, dataSink);
        }
    }) {        
    
        //You can use the compressed input stream here
    
    } catch (final IOException e) {
        //Handle exceptions here
    } 
    

提交回复
热议问题