Search in sources :

Example 1 with IntelDeflater

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);
    }
}
Also used : IntelDeflaterFactory(com.intel.gkl.compression.IntelDeflaterFactory) IntelDeflater(com.intel.gkl.compression.IntelDeflater) Deflater(java.util.zip.Deflater) IntelInflaterFactory(com.intel.gkl.compression.IntelInflaterFactory) RandomDNA(org.broadinstitute.hellbender.utils.RandomDNA) Inflater(java.util.zip.Inflater) IntelInflater(com.intel.gkl.compression.IntelInflater) SkipException(org.testng.SkipException) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Aggregations

IntelDeflater (com.intel.gkl.compression.IntelDeflater)1 IntelDeflaterFactory (com.intel.gkl.compression.IntelDeflaterFactory)1 IntelInflater (com.intel.gkl.compression.IntelInflater)1 IntelInflaterFactory (com.intel.gkl.compression.IntelInflaterFactory)1 Deflater (java.util.zip.Deflater)1 Inflater (java.util.zip.Inflater)1 RandomDNA (org.broadinstitute.hellbender.utils.RandomDNA)1 BaseTest (org.broadinstitute.hellbender.utils.test.BaseTest)1 SkipException (org.testng.SkipException)1 Test (org.testng.annotations.Test)1