mirror of
https://github.com/xerial/snappy-java.git
synced 2025-04-08 19:35:08 +02:00
#25 Add raw compress methods that take memory addresses
This commit is contained in:
parent
dd0f4d9d9c
commit
f0e0e9727e
@ -320,6 +320,31 @@ public class Snappy
|
|||||||
return ((SnappyNativeAPI) impl).maxCompressedLength(byteSize);
|
return ((SnappyNativeAPI) impl).maxCompressedLength(byteSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Zero-copy compress using memory addresses.
|
||||||
|
* @param inputAddr input memory address
|
||||||
|
* @param inputSize input byte size
|
||||||
|
* @param destAddr destination address of the compressed data
|
||||||
|
* @return the compressed data size
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
public static long rawCompress(long inputAddr, long inputSize, long destAddr) throws IOException {
|
||||||
|
return ((SnappyNativeAPI) impl).rawCompress(inputAddr, inputSize, destAddr);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Zero-copy decompress using memory addresses.
|
||||||
|
* @param inputAddr input memory address
|
||||||
|
* @param inputSize input byte size
|
||||||
|
* @param destAddr destination address of the uncompressed data
|
||||||
|
* @return the uncompressed data size
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
public static long rawUncompress(long inputAddr, long inputSize, long destAddr) throws IOException {
|
||||||
|
return ((SnappyNativeAPI) impl).rawUncompress(inputAddr, inputSize, destAddr);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compress the input data and produce a byte array of the uncompressed data
|
* Compress the input data and produce a byte array of the uncompressed data
|
||||||
*
|
*
|
||||||
@ -547,7 +572,7 @@ public class Snappy
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the uncompressed byte size of the given compressed input. This
|
* Get the uncompressed byte size of the given compressed input. This
|
||||||
* operation taks O(1) time.
|
* operation takes O(1) time.
|
||||||
*
|
*
|
||||||
* @param compressed
|
* @param compressed
|
||||||
* input data [pos() ... limit())
|
* input data [pos() ... limit())
|
||||||
@ -565,6 +590,18 @@ public class Snappy
|
|||||||
return ((SnappyNativeAPI) impl).uncompressedLength(compressed, compressed.position(), compressed.remaining());
|
return ((SnappyNativeAPI) impl).uncompressedLength(compressed, compressed.position(), compressed.remaining());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the uncompressed byte size of the given compressed input. This operation takes O(1) time.
|
||||||
|
* @param inputAddr compressed data address
|
||||||
|
* @param len byte length of the input
|
||||||
|
* @return uncompressed byte length of the given input
|
||||||
|
* @throws IOException when failed to uncompress the given input. The error code is
|
||||||
|
* {@link SnappyErrorCode#PARSING_ERROR}
|
||||||
|
*/
|
||||||
|
public static long uncompressedLength(long inputAddr, long len) throws IOException {
|
||||||
|
return ((SnappyNativeAPI) impl).uncompressedLength(inputAddr, len);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Uncompress the input as a float array
|
* Uncompress the input as a float array
|
||||||
*
|
*
|
||||||
|
@ -36,6 +36,32 @@ JNIEXPORT jstring JNICALL Java_org_xerial_snappy_SnappyNative_nativeLibraryVersi
|
|||||||
return env->NewStringUTF("1.0.4");
|
return env->NewStringUTF("1.0.4");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
JNIEXPORT jlong JNICALL Java_org_xerial_snappy_SnappyNative_rawCompress__JJJ
|
||||||
|
(JNIEnv* env, jobject self, jlong srcAddr, jlong length, jlong destAddr) {
|
||||||
|
size_t compressedLength;
|
||||||
|
snappy::RawCompress((char*) srcAddr, (size_t) length, (char*) destAddr, &compressedLength);
|
||||||
|
return (jlong) compressedLength;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
JNIEXPORT jlong JNICALL Java_org_xerial_snappy_SnappyNative_rawUncompress__JJJ
|
||||||
|
(JNIEnv* env, jobject self, jlong srcAddr, jlong length, jlong destAddr) {
|
||||||
|
|
||||||
|
size_t uncompressedLength;
|
||||||
|
snappy::GetUncompressedLength((char*) srcAddr, (size_t) length, &uncompressedLength);
|
||||||
|
bool ret = snappy::RawUncompress((char*) srcAddr, (size_t) length, (char*) destAddr);
|
||||||
|
|
||||||
|
if(!ret) {
|
||||||
|
throw_exception(env, self, 5);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (jlong) uncompressedLength;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Class: org_xerial_snappy_Snappy
|
* Class: org_xerial_snappy_Snappy
|
||||||
* Method: compress
|
* Method: compress
|
||||||
@ -190,6 +216,21 @@ JNIEXPORT jint JNICALL Java_org_xerial_snappy_SnappyNative_uncompressedLength__L
|
|||||||
return (jint) result;
|
return (jint) result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
JNIEXPORT jlong JNICALL Java_org_xerial_snappy_SnappyNative_uncompressedLength__JJ
|
||||||
|
(JNIEnv *env, jobject self, jlong inputAddr, jlong len) {
|
||||||
|
|
||||||
|
|
||||||
|
size_t result;
|
||||||
|
bool ret = snappy::GetUncompressedLength((char*) inputAddr, (size_t) len, &result);
|
||||||
|
if(!ret) {
|
||||||
|
throw_exception(env, self, 2);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (jint) result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
JNIEXPORT jboolean JNICALL Java_org_xerial_snappy_SnappyNative_isValidCompressedBuffer__Ljava_nio_ByteBuffer_2II
|
JNIEXPORT jboolean JNICALL Java_org_xerial_snappy_SnappyNative_isValidCompressedBuffer__Ljava_nio_ByteBuffer_2II
|
||||||
(JNIEnv * env, jobject self, jobject compressed, jint cpos, jint clen)
|
(JNIEnv * env, jobject self, jobject compressed, jint cpos, jint clen)
|
||||||
{
|
{
|
||||||
|
@ -15,6 +15,22 @@ extern "C" {
|
|||||||
JNIEXPORT jstring JNICALL Java_org_xerial_snappy_SnappyNative_nativeLibraryVersion
|
JNIEXPORT jstring JNICALL Java_org_xerial_snappy_SnappyNative_nativeLibraryVersion
|
||||||
(JNIEnv *, jobject);
|
(JNIEnv *, jobject);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Class: org_xerial_snappy_SnappyNative
|
||||||
|
* Method: rawCompress
|
||||||
|
* Signature: (JJJ)J
|
||||||
|
*/
|
||||||
|
JNIEXPORT jlong JNICALL Java_org_xerial_snappy_SnappyNative_rawCompress__JJJ
|
||||||
|
(JNIEnv *, jobject, jlong, jlong, jlong);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Class: org_xerial_snappy_SnappyNative
|
||||||
|
* Method: rawUncompress
|
||||||
|
* Signature: (JJJ)J
|
||||||
|
*/
|
||||||
|
JNIEXPORT jlong JNICALL Java_org_xerial_snappy_SnappyNative_rawUncompress__JJJ
|
||||||
|
(JNIEnv *, jobject, jlong, jlong, jlong);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Class: org_xerial_snappy_SnappyNative
|
* Class: org_xerial_snappy_SnappyNative
|
||||||
* Method: rawCompress
|
* Method: rawCompress
|
||||||
@ -71,6 +87,14 @@ JNIEXPORT jint JNICALL Java_org_xerial_snappy_SnappyNative_uncompressedLength__L
|
|||||||
JNIEXPORT jint JNICALL Java_org_xerial_snappy_SnappyNative_uncompressedLength__Ljava_lang_Object_2II
|
JNIEXPORT jint JNICALL Java_org_xerial_snappy_SnappyNative_uncompressedLength__Ljava_lang_Object_2II
|
||||||
(JNIEnv *, jobject, jobject, jint, jint);
|
(JNIEnv *, jobject, jobject, jint, jint);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Class: org_xerial_snappy_SnappyNative
|
||||||
|
* Method: uncompressedLength
|
||||||
|
* Signature: (JJ)J
|
||||||
|
*/
|
||||||
|
JNIEXPORT jlong JNICALL Java_org_xerial_snappy_SnappyNative_uncompressedLength__JJ
|
||||||
|
(JNIEnv *, jobject, jlong, jlong);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Class: org_xerial_snappy_SnappyNative
|
* Class: org_xerial_snappy_SnappyNative
|
||||||
* Method: isValidCompressedBuffer
|
* Method: isValidCompressedBuffer
|
||||||
|
@ -48,6 +48,9 @@ public class SnappyNative implements SnappyNativeAPI
|
|||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
// Generic compression/decompression routines.
|
// Generic compression/decompression routines.
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
|
public native long rawCompress(long inputAddr, long inputSize, long destAddr) throws IOException;
|
||||||
|
public native long rawUncompress(long inputAddr, long inputSize, long destAddr) throws IOException;
|
||||||
|
|
||||||
public native int rawCompress(ByteBuffer input, int inputOffset, int inputLength, ByteBuffer compressed,
|
public native int rawCompress(ByteBuffer input, int inputOffset, int inputLength, ByteBuffer compressed,
|
||||||
int outputOffset) throws IOException;
|
int outputOffset) throws IOException;
|
||||||
|
|
||||||
@ -68,6 +71,8 @@ public class SnappyNative implements SnappyNativeAPI
|
|||||||
|
|
||||||
public native int uncompressedLength(Object input, int offset, int len) throws IOException;
|
public native int uncompressedLength(Object input, int offset, int len) throws IOException;
|
||||||
|
|
||||||
|
public native long uncompressedLength(long inputAddr, long len) throws IOException;
|
||||||
|
|
||||||
public native boolean isValidCompressedBuffer(ByteBuffer compressed, int offset, int len) throws IOException;
|
public native boolean isValidCompressedBuffer(ByteBuffer compressed, int offset, int len) throws IOException;
|
||||||
|
|
||||||
public native boolean isValidCompressedBuffer(Object input, int offset, int len) throws IOException;
|
public native boolean isValidCompressedBuffer(Object input, int offset, int len) throws IOException;
|
||||||
|
@ -45,6 +45,9 @@ public interface SnappyNativeAPI
|
|||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
// Generic compression/decompression routines.
|
// Generic compression/decompression routines.
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
|
public long rawCompress(long inputAddr, long inputSize, long destAddr) throws IOException;
|
||||||
|
public long rawUncompress(long inputAddr, long inputSize, long destAddr) throws IOException;
|
||||||
|
|
||||||
public int rawCompress(ByteBuffer input, int inputOffset, int inputLength, ByteBuffer compressed, int outputOffset)
|
public int rawCompress(ByteBuffer input, int inputOffset, int inputLength, ByteBuffer compressed, int outputOffset)
|
||||||
throws IOException;
|
throws IOException;
|
||||||
|
|
||||||
@ -65,6 +68,9 @@ public interface SnappyNativeAPI
|
|||||||
|
|
||||||
public int uncompressedLength(Object input, int offset, int len) throws IOException;
|
public int uncompressedLength(Object input, int offset, int len) throws IOException;
|
||||||
|
|
||||||
|
public long uncompressedLength(long inputAddr, long len) throws IOException;
|
||||||
|
|
||||||
|
|
||||||
public boolean isValidCompressedBuffer(ByteBuffer compressed, int offset, int len) throws IOException;
|
public boolean isValidCompressedBuffer(ByteBuffer compressed, int offset, int len) throws IOException;
|
||||||
|
|
||||||
public boolean isValidCompressedBuffer(Object input, int offset, int len) throws IOException;
|
public boolean isValidCompressedBuffer(Object input, int offset, int len) throws IOException;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user