Deflater: setLevel(int level) : Deflater « java.util.zip « Java by API






Deflater: setLevel(int level)

 

 
import java.io.ByteArrayOutputStream;
import java.util.zip.Deflater;

public class Main {
  public static void main(String[] argv) throws Exception {
    byte[] input = "asdf".getBytes();

    Deflater compressor = new Deflater();
    compressor.setLevel(Deflater.BEST_COMPRESSION);

    compressor.setInput(input);
    compressor.finish();

    ByteArrayOutputStream bos = new ByteArrayOutputStream(input.length);

    byte[] buf = new byte[1024];
    while (!compressor.finished()) {
      int count = compressor.deflate(buf);
      bos.write(buf, 0, count);
    }
    bos.close();
    byte[] compressedData = bos.toByteArray();
  }
}

   
  








Related examples in the same category

1.Deflater.BEST_COMPRESSION
2.Deflater: deflate(byte[] b)
3.Deflater: finish()
4.Deflater: setInput(byte[] b)