@Test
public void testCompression() {

    final File comF = TestUtils.getPath("compression").resolve("compressed.gz").toFile();
    final File decF = TestUtils.getPath("compression").resolve("decompressed.jpg").toFile();
    try {
        final File uncF = TestUtils.getPath("compression/uncompressed.jpg").toFile();
        final byte[] buffer = new byte[512];
        //Compress
        try (GZIPCompressingInputStream cfis = new GZIPCompressingInputStream(new FileInputStream(uncF));
             FileOutputStream fos = new FileOutputStream(comF))
        {
          int r = 0;
          while ( (r = cfis.read(buffer, 0, 512)) > 0 ) {
              fos.write(buffer, 0, r);
          }
        }
        // Decompress
        try (GZIPInputStream decfis = new GZIPInputStream(new FileInputStream(comF));
             FileOutputStream fos = new FileOutputStream(decF))
        {
          int r = 0;
          while ( (r = decfis.read(buffer, 0, 512)) > 0 ) {
              fos.write(buffer, 0, r);
          }
        }
        //Compare
        try (FileInputStream fis1 = new FileInputStream(uncF);
            FileInputStream fis2 = new FileInputStream(decF))
        {
          final byte[] buffer2 = new byte[512];
          int r = 0;
          int r2 = 0;
          while ( ((r = fis1.read(buffer, 0, 512)) > 0) & ((r2 = fis2.read(buffer2, 0, 512)) > 0)) {
              assertEquals(r, r2);
              assertArrayEquals(buffer, buffer2);
          }
          assertEquals(r, r2);
        }
    } catch (final IOException ex) {
        Logger.getLogger(GZIPCompressingInputStreamTest.class.getName()).log(Level.SEVERE, null, ex);
        fail();
    } finally {
        if (comF.exists())
            comF.delete();
        if (decF.exists())
            decF.delete();
    }
}