Fixes issue 18
This commit is contained in:
parent
6fcda4dd88
commit
dd7c61a4f3
|
@ -85,14 +85,14 @@ Mac-x86_64_SNAPPY_FLAGS :=
|
|||
|
||||
Windows-x86_CXX := mingw32-g++
|
||||
Windows-x86_STRIP := strip
|
||||
Windows-x86_CXXFLAGS := -Ilib/inc_win -O2
|
||||
Windows-x86_CXXFLAGS := -Ilib/inc_win -O2
|
||||
Windows-x86_LINKFLAGS := -Wl,--kill-at -shared -static
|
||||
Windows-x86_LIBNAME := snappyjava.dll
|
||||
Windows-x86_SNAPPY_FLAGS :=
|
||||
|
||||
Windows-amd64_CXX := x86_64-w64-mingw32-g++
|
||||
Windows-amd64_STRIP := x86_64-w64-mingw32-strip
|
||||
Windows-amd64_CXXFLAGS := -Ilib/inc_win -O2
|
||||
Windows-amd64_CXXFLAGS := -Ilib/inc_win -O2
|
||||
Windows-amd64_LINKFLAGS := -Wl,--kill-at -shared -static
|
||||
Windows-amd64_LIBNAME := snappyjava.dll
|
||||
Windows-amd64_SNAPPY_FLAGS :=
|
||||
|
|
|
@ -166,6 +166,16 @@ public class Snappy
|
|||
return SnappyNative.isValidCompressedBuffer(input, offset, length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true iff the contents of compressed buffer [offset,
|
||||
* offset+length) can be uncompressed successfully. Does not return the
|
||||
* uncompressed data. Takes time proportional to the input length, but is
|
||||
* usually at least a factor of four faster than actual decompression.
|
||||
*/
|
||||
public static boolean isValidCompressedBuffer(byte[] input) throws SnappyException {
|
||||
return isValidCompressedBuffer(input, 0, input.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true iff the contents of compressed buffer [pos() ... limit())
|
||||
* can be uncompressed successfully. Does not return the uncompressed data.
|
||||
|
|
|
@ -37,7 +37,8 @@ public enum SnappyErrorCode {
|
|||
FAILED_TO_LOAD_NATIVE_LIBRARY(1),
|
||||
PARSING_ERROR(2),
|
||||
NOT_A_DIRECT_BUFFER(3),
|
||||
OUT_OF_MEMORY(4);
|
||||
OUT_OF_MEMORY(4),
|
||||
FAILED_TO_UNCOMPRESS(5);
|
||||
|
||||
public final int id;
|
||||
|
||||
|
|
|
@ -19,19 +19,18 @@
|
|||
|
||||
void throw_exception(JNIEnv *env, jclass self, int errorCode)
|
||||
{
|
||||
jmethodID mth_throwex = 0;
|
||||
jmethodID mth_throwex = env->GetStaticMethodID(self, "throw_error", "(I)V");
|
||||
|
||||
if (!mth_throwex)
|
||||
mth_throwex = env->GetMethodID(self, "throw_error", "(I)V");
|
||||
|
||||
env->CallVoidMethod(self, mth_throwex, (jint) errorCode);
|
||||
if(mth_throwex == 0)
|
||||
return;
|
||||
env->CallStaticVoidMethod(self, mth_throwex, (jint) errorCode);
|
||||
}
|
||||
|
||||
|
||||
JNIEXPORT jstring JNICALL Java_org_xerial_snappy_SnappyNative_nativeLibraryVersion
|
||||
(JNIEnv * env, jclass self)
|
||||
{
|
||||
return env->NewStringUTF("1.0.1");
|
||||
return env->NewStringUTF("1.0.3");
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -94,7 +93,7 @@ JNIEXPORT jint JNICALL Java_org_xerial_snappy_SnappyNative_rawUncompress__Ljava_
|
|||
env->ReleasePrimitiveArrayCritical((jarray) output, out, 0);
|
||||
|
||||
if(!ret) {
|
||||
throw_exception(env, self, 2);
|
||||
throw_exception(env, self, 5);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -121,7 +120,7 @@ JNIEXPORT jint JNICALL Java_org_xerial_snappy_SnappyNative_rawUncompress__Ljava_
|
|||
snappy::GetUncompressedLength(compressedBuffer + cpos, (size_t) clen, &decompressedLength);
|
||||
bool ret = snappy::RawUncompress(compressedBuffer + cpos, (size_t) clen, decompressedBuffer + dpos);
|
||||
if(!ret) {
|
||||
throw_exception(env, self, 2);
|
||||
throw_exception(env, self, 5);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -180,6 +179,11 @@ JNIEXPORT jint JNICALL Java_org_xerial_snappy_SnappyNative_uncompressedLength__L
|
|||
bool ret = snappy::GetUncompressedLength(in + offset, (size_t) length, &result);
|
||||
env->ReleasePrimitiveArrayCritical((jarray) input, in, 0);
|
||||
|
||||
if(!ret) {
|
||||
throw_exception(env, self, 2);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return (jint) result;
|
||||
}
|
||||
|
||||
|
|
Binary file not shown.
|
@ -287,8 +287,15 @@ public class SnappyTest
|
|||
public void isValidCompressedData() throws Exception {
|
||||
|
||||
byte[] b = new byte[] { (byte) 91, (byte) 34, (byte) 80, (byte) 73, (byte) 34, (byte) 93 };
|
||||
if (Snappy.isValidCompressedBuffer(b, 0, b.length)) {
|
||||
|
||||
assertFalse(Snappy.isValidCompressedBuffer(b));
|
||||
|
||||
try {
|
||||
byte[] uncompressed = Snappy.uncompress(b);
|
||||
fail("cannot reach here since the input is invalid data");
|
||||
}
|
||||
catch (SnappyException e) {
|
||||
assertEquals(SnappyErrorCode.FAILED_TO_UNCOMPRESS, e.errorCode);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue