Skip to content

Commit

Permalink
InflaterFactory added
Browse files Browse the repository at this point in the history
  • Loading branch information
pnvaidya committed Feb 2, 2017
1 parent 7be8116 commit a68ccd1
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/main/java/com/intel/gkl/compression/IntelDeflater.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
8 changes: 5 additions & 3 deletions src/main/java/com/intel/gkl/compression/IntelInflater.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();

/**
Expand Down Expand Up @@ -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;
}

Expand All @@ -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);
}

/**
Expand All @@ -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);
}

/**
Expand Down
13 changes: 8 additions & 5 deletions src/main/native/compression/IntelInflater.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;



Expand All @@ -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");

}

Expand All @@ -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;
Expand All @@ -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)
{


Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/main/native/compression/IntelInflater.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a68ccd1

Please sign in to comment.