Code example for DeflaterOutputStream

0
  @Override 
  public byte[] compress(byte[] value, int offset, int length)
      throws IOException { 
     
    ByteArrayOutputStream baos = new ByteArrayOutputStream(MathUtils.nextPowOfTwo(length));
    try (OutputStream out = new DeflaterOutputStream(baos)) {
      out.write(value, offset, length);
    } finally { 
      IoUtils.closeAll(baos);
    } 
     
    return baos.toByteArray();
  } 
 
  @Override 
  public byte[] decompress(byte[] value, int offset, int length)
      throws IOException { 
     
    ByteArrayOutputStream baos = new ByteArrayOutputStream(MathUtils.nextPowOfTwo(2 * length));
    try (OutputStream out = new InflaterOutputStream(baos)) {
      out.write(value, offset, length);