-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #45 from Intel-HLS/pv_inflaterfactory
Pv inflaterfactory
- Loading branch information
Showing
10 changed files
with
145 additions
and
20 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
src/main/java/com/intel/gkl/compression/IntelInflaterFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.intel.gkl.compression; | ||
|
||
import htsjdk.samtools.util.zip.InflaterFactory; | ||
|
||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
|
||
import java.io.File; | ||
import java.util.zip.Inflater; | ||
|
||
/** | ||
* Created by pnvaidya on 2/1/17. | ||
*/ | ||
public class IntelInflaterFactory extends InflaterFactory { | ||
private final static Logger logger = LogManager.getLogger(IntelDeflaterFactory.class); | ||
private boolean intelInflaterSupported; | ||
|
||
public IntelInflaterFactory(File tmpDir) { | ||
intelInflaterSupported = new IntelInflater().load(tmpDir); | ||
} | ||
|
||
public IntelInflaterFactory() { | ||
this(null); | ||
} | ||
|
||
public Inflater makeInflater(final boolean nowrap) { | ||
if (intelInflaterSupported && nowrap) { | ||
return new IntelInflater(nowrap); | ||
} | ||
logger.warn("IntelInflater is not supported, using Java.util.zip.Inflater"); | ||
return new Inflater(nowrap); | ||
} | ||
|
||
public boolean usingIntelInflater() { | ||
return intelInflaterSupported; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
src/test/java/com/intel/gkl/compression/InflaterUnitTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package com.intel.gkl.compression; | ||
|
||
import com.intel.gkl.IntelGKLUtils; | ||
import htsjdk.samtools.util.BlockCompressedInputStream; | ||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.testng.Assert; | ||
import org.testng.annotations.Test; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.util.zip.Deflater; | ||
import java.util.zip.Inflater; | ||
|
||
/** | ||
* Created by pnvaidya on 2/1/17. | ||
*/ | ||
public class InflaterUnitTest { | ||
|
||
private final static Logger log = LogManager.getLogger(InflaterUnitTest.class); | ||
private final static String INPUT_FILE = IntelGKLUtils.pathToTestResource("HiSeq.1mb.1RG.2k_lines.bam"); | ||
|
||
@Test(enabled = true) | ||
public void inflaterUnitTest() throws IOException { | ||
|
||
final File inputFile = new File(INPUT_FILE); | ||
|
||
long inputBytes = inputFile.length(); | ||
int compressedBytes = 0; | ||
final byte[] inputbuffer = new byte[(int)inputBytes]; | ||
final byte[] outputbuffer = new byte[(int)inputBytes]; | ||
final byte[] finalbuffer = new byte[(int)inputBytes]; | ||
|
||
long totalTime = 0; | ||
|
||
for (int i = 1; i < 10; i++) { | ||
|
||
final IntelInflaterFactory intelInflaterFactory = new IntelInflaterFactory(); | ||
final Inflater inflater = intelInflaterFactory.makeInflater(true); | ||
|
||
final IntelDeflaterFactory intelDeflaterFactory = new IntelDeflaterFactory(); | ||
final Deflater deflater = intelDeflaterFactory.makeDeflater(i, true); | ||
|
||
|
||
final BlockCompressedInputStream inputStream = new BlockCompressedInputStream(inputFile); | ||
|
||
inputBytes = inputStream.read(inputbuffer, 0, inputbuffer.length); | ||
deflater.reset(); | ||
deflater.setInput(inputbuffer, 0, inputbuffer.length); | ||
deflater.finish(); | ||
compressedBytes = deflater.deflate(outputbuffer, 0, outputbuffer.length); | ||
|
||
|
||
try { | ||
inflater.reset(); | ||
inflater.setInput(outputbuffer, 0, compressedBytes); | ||
final long start = System.currentTimeMillis(); | ||
inflater.inflate(finalbuffer, 0, inputbuffer.length); | ||
totalTime = System.currentTimeMillis() - start; | ||
System.out.printf("Level: %d, time: %d\n", i, totalTime); | ||
|
||
|
||
} catch (java.util.zip.DataFormatException e) { | ||
e.printStackTrace(); | ||
} | ||
Assert.assertEquals(inputbuffer, finalbuffer); | ||
inflater.end(); | ||
deflater.end(); | ||
} | ||
|
||
|
||
} | ||
} |