title: How do Java deflation/inflation streams work?
body: <p>I'm trying to compress and decompress some bytes of data with the Deflater and InflaterOutputStream.</p>
  
  <p>The problem is that compression seems to work (I'm not
  sure since the compressed data is always the same even if I have random test data).
  But the decompression return nothing at all.</p>
  
  <p>What am I doing wrong?</p>
  
  <p>My console output:</p>
  
  <p>Test data: D8A8E00821608F227AE473774E177216</p>
  
  <p>Compressed data: 789C</p>
  
  <p>Decompressed data: </p>
  
  <p>My program:</p>
  
  <pre><code>SecureRandom random = new SecureRandom();
  byte[] testdata = new byte[16];
  random.nextBytes(testdata);
  System.out.println("Test data: " + DatatypeConverter.printHexBinary(testdata));
  
  byte[] compressed = null;
  try (ByteArrayOutputStream buffer = new ByteArrayOutputStream())
  {
     try (DeflaterOutputStream stream = new DeflaterOutputStream(buffer))
     {
        stream.write(testdata);
        stream.flush();
        compressed = buffer.toByteArray();
        System.out.println("Compressed data: " + DatatypeConverter.printHexBinary(compressed));
     }
  }
  catch (IOException e)
  {
     System.out.println("IOException during compression.");
  }
  
  byte[] decompressed = null;
  try (ByteArrayOutputStream buffer = new ByteArrayOutputStream())
  {
     try (InflaterOutputStream stream = new InflaterOutputStream(buffer))
     {
        stream.write(compressed);
        stream.flush();
        decompressed = buffer.toByteArray();
        System.out.println("Decompressed data: " + DatatypeConverter.printHexBinary(decompressed));
     }
  }
  catch (IOException e)
  {
     System.out.println("IOException during decompression.");
  }
  </code></pre>