use of com.intel.gkl.compression.IntelDeflater in project gatk by broadinstitute.
the class IntelInflaterDeflaterIntegrationTest method deflateInflateWithIntel.
@Test
public void deflateInflateWithIntel() throws DataFormatException {
if (!isIntelInflaterDeflaterSupported()) {
throw new SkipException("IntelInflater/IntelDeflater not available on this platform");
}
// create buffers and random input
final int LEN = 64 * 1024;
final byte[] input = new RandomDNA().nextBases(LEN);
final byte[] compressed = new byte[2 * LEN];
final byte[] result = new byte[LEN];
final IntelInflaterFactory intelInflaterFactory = new IntelInflaterFactory();
final IntelDeflaterFactory intelDeflaterFactory = new IntelDeflaterFactory();
Assert.assertTrue(intelInflaterFactory.usingIntelInflater());
Assert.assertTrue(intelDeflaterFactory.usingIntelDeflater());
for (int i = 0; i < 10; i++) {
// create deflater with compression level i
final Deflater deflater = intelDeflaterFactory.makeDeflater(i, true);
// setup deflater
deflater.setInput(input);
deflater.finish();
// compress data
int compressedBytes = 0;
// so this loop should always finish in one iteration
while (!deflater.finished()) {
compressedBytes = deflater.deflate(compressed, 0, compressed.length);
}
deflater.end();
// decompress and check output == input
Inflater inflater = intelInflaterFactory.makeInflater(true);
inflater.setInput(compressed, 0, compressedBytes);
inflater.inflate(result);
inflater.end();
Assert.assertEquals(input, result);
// clear compressed and result buffers for next iteration
Arrays.fill(compressed, (byte) 0);
Arrays.fill(result, (byte) 0);
}
}
Aggregations