class DeflateCompressor implements Compressor {

  @Override
  public void compress(InputStream uncompressedIn, OutputStream compressedOut) throws IOException {
    byte[] buffer = new byte[inputBufferSize];
    DeflaterOutputStream deflaterOut =
        new DeflaterOutputStream(compressedOut, createOrResetDeflater(), outputBufferSize);
    int numRead = 0;
    while ((numRead = uncompressedIn.read(buffer)) >= 0) {
      deflaterOut.write(buffer, 0, numRead);
    }
    deflaterOut.finish();
    deflaterOut.flush();
  }

}