diff --git a/src/main/java/com/intel/gkl/compression/IntelDeflater.java b/src/main/java/com/intel/gkl/compression/IntelDeflater.java index 4953e547..9b2d5736 100644 --- a/src/main/java/com/intel/gkl/compression/IntelDeflater.java +++ b/src/main/java/com/intel/gkl/compression/IntelDeflater.java @@ -96,6 +96,7 @@ public IntelDeflater(int level, boolean nowrap) { this.level = level; this.nowrap = nowrap; strategy = DEFAULT_STRATEGY; + } /** @@ -135,6 +136,7 @@ public void reset() { */ @Override public void setInput(byte[] b, int off, int len) throws NullPointerException { + if(lz_stream == 0) reset(); if(b == null) { throw new NullPointerException("Input is null"); } @@ -144,8 +146,6 @@ public void setInput(byte[] b, int off, int len) throws NullPointerException { inputBuffer = b; inputBufferLength = len; - - } /** diff --git a/src/main/java/com/intel/gkl/compression/IntelInflater.java b/src/main/java/com/intel/gkl/compression/IntelInflater.java index f19c3929..9b74869e 100644 --- a/src/main/java/com/intel/gkl/compression/IntelInflater.java +++ b/src/main/java/com/intel/gkl/compression/IntelInflater.java @@ -88,6 +88,7 @@ public synchronized boolean load(File tempDir) { public IntelInflater(boolean nowrap) { // initFieldsNative(); this.nowrap = nowrap; + } /** @@ -116,6 +117,7 @@ public void reset() { */ @Override public void setInput(byte[] b, int off, int len) throws NullPointerException { + if(lz_stream == 0) reset(); if(b == null) { throw new NullPointerException("Input is null"); } @@ -125,6 +127,7 @@ public void setInput(byte[] b, int off, int len) throws NullPointerException { inputBuffer = b; inputBufferOffset = off; inputBufferLength = len; + } /** @@ -152,7 +155,7 @@ public int inflate (byte[] b, int off, int len ) { */ @Override public int inflate (byte[] b ) { - return inflateNative( b, 0, 0); + return inflateNative( b, 0, b.length); } /** @@ -175,6 +178,15 @@ public boolean finished() { */ @Override public void end() { - endNative(); + + if(lz_stream !=0) + { + endNative(); + lz_stream=0; + } } + + @Override + protected void finalize() {} + } \ No newline at end of file diff --git a/src/test/java/com/intel/gkl/compression/DeflaterUnitTest.java b/src/test/java/com/intel/gkl/compression/DeflaterUnitTest.java index 5673ec71..6a3f7e03 100644 --- a/src/test/java/com/intel/gkl/compression/DeflaterUnitTest.java +++ b/src/test/java/com/intel/gkl/compression/DeflaterUnitTest.java @@ -82,7 +82,6 @@ public void randomDNATest() { randomDNA(input); - deflater.reset(); deflater.setInput(input, 0, input.length); deflater.finish(); @@ -98,7 +97,7 @@ public void randomDNATest() { try { - inflater.reset(); + inflater.setInput(compressed, 0, compressedBytes); final long start = System.currentTimeMillis(); inflater.inflate(result, 0, LEN);