Code example for GZIPOutputStream

Methods: close, write

0
 
    @Override 
    protected byte[] doCompress(byte[] plain) throws IOException {
 
        @Cleanup ByteArrayOutputStream bos = new ByteArrayOutputStream();
        @Cleanup GZIPOutputStream gzip = new GZIPOutputStream(bos);
 
        gzip.write(plain);
        gzip.close();
 
        return bos.toByteArray();
 
    } 
 
    @Override 
    protected byte[] doDecompress(byte[] compressed) throws IOException {
 
        @Cleanup 
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        @Cleanup 
        ByteArrayInputStream bis = new ByteArrayInputStream(compressed);