diff --git a/src/main/java/com/intel/gkl/compression/IntelDeflater.java b/src/main/java/com/intel/gkl/compression/IntelDeflater.java index ed06a963..ec29e6f2 100644 --- a/src/main/java/com/intel/gkl/compression/IntelDeflater.java +++ b/src/main/java/com/intel/gkl/compression/IntelDeflater.java @@ -139,6 +139,7 @@ public void setInput(byte[] b, int off, int len) throws NullPointerException { if(len <= 0) { throw new NullPointerException("Input buffer length is zero."); } + 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 d3c3b284..f19c3929 100644 --- a/src/main/java/com/intel/gkl/compression/IntelInflater.java +++ b/src/main/java/com/intel/gkl/compression/IntelInflater.java @@ -69,12 +69,13 @@ public synchronized boolean load(File tempDir) { private long lz_stream; private byte[] inputBuffer; private int inputBufferLength; + private int inputBufferOffset; private boolean finished; private boolean nowrap; private static native void initNative(); private native void resetNative(boolean nowrap); - private native int inflateNative( byte[] b, int len); + private native int inflateNative( byte[] b, int off, int len); private native void endNative(); /** @@ -122,6 +123,7 @@ public void setInput(byte[] b, int off, int len) throws NullPointerException { throw new NullPointerException("Input buffer length is zero."); } inputBuffer = b; + inputBufferOffset = off; inputBufferLength = len; } @@ -139,7 +141,7 @@ public void setInput(byte[] b, int off, int len) throws NullPointerException { */ @Override public int inflate (byte[] b, int off, int len ) { - return inflateNative(b, len); + return inflateNative(b, off, len); } /** @@ -150,7 +152,7 @@ public int inflate (byte[] b, int off, int len ) { */ @Override public int inflate (byte[] b ) { - return inflateNative( b, 0); + return inflateNative( b, 0, 0); } /** diff --git a/src/main/native/compression/IntelInflater.cc b/src/main/native/compression/IntelInflater.cc index bbf005b1..fba9b168 100644 --- a/src/main/native/compression/IntelInflater.cc +++ b/src/main/native/compression/IntelInflater.cc @@ -51,6 +51,7 @@ static jfieldID FID_inf_lz_stream; static jfieldID FID_inf_inputBuffer; static jfieldID FID_inf_inputBufferLength; static jfieldID FID_inf_finished; +static jfieldID FID_inf_inputBufferOffset; @@ -63,6 +64,7 @@ JNIEXPORT void JNICALL Java_com_intel_gkl_compression_IntelInflater_initNative FID_inf_inputBuffer = env->GetFieldID(cls, "inputBuffer", "[B"); FID_inf_inputBufferLength = env->GetFieldID(cls, "inputBufferLength", "I"); FID_inf_finished = env->GetFieldID(cls, "finished", "Z"); + FID_inf_inputBufferOffset = env->GetFieldID(cls, "inputBufferOffset", "I"); } @@ -82,8 +84,6 @@ JNIEXPORT void JNICALL Java_com_intel_gkl_compression_IntelInflater_resetNative env->SetLongField(obj, FID_inf_lz_stream, (jlong)lz_stream); - - isal_inflate_init(lz_stream); lz_stream->avail_in = 0; @@ -97,7 +97,7 @@ JNIEXPORT void JNICALL Java_com_intel_gkl_compression_IntelInflater_resetNative JNIEXPORT jint JNICALL Java_com_intel_gkl_compression_IntelInflater_inflateNative -(JNIEnv * env, jobject obj, jbyteArray outputBuffer, jint outputBufferLength) +(JNIEnv * env, jobject obj, jbyteArray outputBuffer, jint outputBufferOffset, jint outputBufferLength) { @@ -106,13 +106,16 @@ JNIEXPORT jint JNICALL Java_com_intel_gkl_compression_IntelInflater_inflateNativ jbyteArray inputBuffer = (jbyteArray)env->GetObjectField(obj, FID_inf_inputBuffer); jint inputBufferLength = env->GetIntField(obj, FID_inf_inputBufferLength); + jint inputBufferOffset = env->GetIntField(obj, FID_inf_inputBufferOffset); + jbyte* next_in = (jbyte*)env->GetPrimitiveArrayCritical(inputBuffer, 0); jbyte* next_out = (jbyte*)env->GetPrimitiveArrayCritical(outputBuffer, 0); - lz_stream->next_in = (Bytef *) next_in; + + lz_stream->next_in = (Bytef *) (next_in + inputBufferOffset); lz_stream->avail_in = (uInt) inputBufferLength; - lz_stream->next_out = (Bytef *) next_out; + lz_stream->next_out = (Bytef *) (next_out + outputBufferOffset); lz_stream->avail_out = (uInt) outputBufferLength; int bytes_in = inputBufferLength; diff --git a/src/main/native/compression/IntelInflater.h b/src/main/native/compression/IntelInflater.h index cfa2c6ae..9aa2e677 100644 --- a/src/main/native/compression/IntelInflater.h +++ b/src/main/native/compression/IntelInflater.h @@ -29,7 +29,7 @@ JNIEXPORT void JNICALL Java_com_intel_gkl_compression_IntelInflater_resetNative * Signature: ([BI)I */ JNIEXPORT jint JNICALL Java_com_intel_gkl_compression_IntelInflater_inflateNative - (JNIEnv *, jobject, jbyteArray, jint); + (JNIEnv *, jobject, jbyteArray, jint, jint); /* * Class: com_intel_gkl_compression_IntelInflater