fork download
  1. import java.util.*;
  2. import java.util.zip.*;
  3. import java.lang.*;
  4.  
  5. class Main
  6. {
  7. public static void test1 () throws Exception {
  8. byte[] output = new byte[20];
  9. Deflater compresser = new Deflater();
  10. compresser.setLevel(Deflater.BEST_COMPRESSION);
  11. compresser.setInput("blah".getBytes("UTF-8"));
  12. compresser.finish();
  13. while ( ! compresser.finished() ) {
  14. int len = compresser.deflate(output);
  15. System.out.println("len="+ len+ " " +Arrays.toString(output));
  16. }
  17. }
  18. public static void test2 () throws Exception {
  19. byte[] output = new byte[20];
  20. Deflater compresser = new Deflater(Deflater.BEST_COMPRESSION);
  21. compresser.setLevel(Deflater.BEST_COMPRESSION);
  22. compresser.setInput("blah".getBytes("UTF-8"));
  23. compresser.finish();
  24. while ( ! compresser.finished() ) {
  25. int len = compresser.deflate(output);
  26. System.out.println("len="+ len+ " " +Arrays.toString(output));
  27. }
  28. }
  29. public static void main (String[] args) throws java.lang.Exception
  30. {
  31. test1();
  32. test2();
  33. }
  34. }
Success #stdin #stdout 0.14s 56028KB
stdin
Standard input is empty
stdout
len=0 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
len=12 [120, -38, 75, -54, 73, -52, 0, 0, 3, -6, 1, -104, 0, 0, 0, 0, 0, 0, 0, 0]
len=12 [120, -38, 75, -54, 73, -52, 0, 0, 3, -6, 1, -104, 0, 0, 0, 0, 0, 0, 0, 0]