Author: mturk Date: Tue Aug 30 12:03:52 2011 New Revision: 1163178 URL: http://svn.apache.org/viewvc?rev=1163178&view=rev Log: Modify copy/paste bzip2 api to better suite zlib api
Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/util/zlib/ZlibImpl.java commons/sandbox/runtime/trunk/src/main/native/shared/zlib.c Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/util/zlib/ZlibImpl.java URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/util/zlib/ZlibImpl.java?rev=1163178&r1=1163177&r2=1163178&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/util/zlib/ZlibImpl.java (original) +++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/util/zlib/ZlibImpl.java Tue Aug 30 12:03:52 2011 @@ -36,12 +36,6 @@ import org.apache.commons.runtime.util.S final class ZlibImpl { - /* flush modes */ - public static final int Z_PARTIAL_FLUSH = 1; - public static final int Z_SYNC_FLUSH = 2; - public static final int Z_FULL_FLUSH = 3; - - private static native int init0(); public static native long newHandle(int bufferSize) throws OutOfMemoryError; @@ -59,12 +53,28 @@ final class ZlibImpl public static native boolean needsInput(long handle); public static native long getTotalIn(long handle); public static native long getTotalOut(long handle); - public static native boolean flush(long handle, int mode); - public static native boolean finish(long handle); public static native boolean finished(long handle); - public static final int DEFAULT_BUFFER_SIZE = 4096; - public static final int DEFAULT_WORK_FACTOR = 30; + public static native int deflate(long handle, int flush); + public static native int inflate(long handle, int flush); + + /* Flush modes */ + public static final int Z_NO_FLUSH = 0; + public static final int Z_PARTIAL_FLUSH = 1; + public static final int Z_SYNC_FLUSH = 2; + public static final int Z_FULL_FLUSH = 3; + + /* Compression levels */ + public static final int Z_NO_COMPRESSION = 0; + public static final int Z_BEST_SPEED = 1; + public static final int Z_BEST_COMPRESSION = 9; + public static final int Z_DEFAULT_COMPRESSION = -1; + + /* Defaults */ + public static final int DEFAULT_BUFFER_SIZE = 8096; + public static final int DEFAULT_MEMLEVEL = 9; + public static final int DEFAULT_WINDOW_SIZE = -15; + public static final int DEFAULT_COMPRESSION = Z_DEFAULT_COMPRESSION; public static final int SIZEOF_Z_STREAM; static { Modified: commons/sandbox/runtime/trunk/src/main/native/shared/zlib.c URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/zlib.c?rev=1163178&r1=1163177&r2=1163178&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/shared/zlib.c (original) +++ commons/sandbox/runtime/trunk/src/main/native/shared/zlib.c Tue Aug 30 12:03:52 2011 @@ -32,6 +32,7 @@ typedef struct acr_zstream { unsigned int blen; int state; jboolean eos; + unsigned long crc; void *next_array; Bytef *next_data; } acr_zstream; @@ -351,34 +352,22 @@ ACR_ZLIB_EXPORT(jboolean, ZlibImpl, need return JNI_FALSE; } -ACR_ZLIB_EXPORT(jboolean, ZlibImpl, finish)(JNI_STDARGS, jlong stream) +ACR_ZLIB_EXPORT(jboolean, ZlibImpl, finished)(JNI_STDARGS, jlong stream) { - jboolean rv = JNI_FALSE; acr_zstream *s = J2P(stream, acr_zstream *); - - if (s->state == 0) { - s->state = Z_FINISH; - rv = JNI_TRUE; - } - return rv; + return s->eos; } -ACR_ZLIB_EXPORT(jboolean, ZlibImpl, flush)(JNI_STDARGS, jlong stream, jint mode) +ACR_ZLIB_EXPORT(jint, ZlibImpl, deflate)(JNI_STDARGS, jlong stream, jint flush) { - jboolean rv = JNI_FALSE; acr_zstream *s = J2P(stream, acr_zstream *); - - if (s->state == 0) { - s->state = mode; - rv = JNI_TRUE; - } - return rv; + return deflate((z_streamp)s, flush); } -ACR_ZLIB_EXPORT(jboolean, ZlibImpl, finished)(JNI_STDARGS, jlong stream) +ACR_ZLIB_EXPORT(jint, ZlibImpl, inflate)(JNI_STDARGS, jlong stream, jint flush) { acr_zstream *s = J2P(stream, acr_zstream *); - return s->eos; + return inflate((z_streamp)s, flush); } ACR_ZLIB_EXPORT(void, ZlibDeflater, close0)(JNI_STDARGS, jlong stream)