compress/decompress test

This commit is contained in:
Taro L. Saito 2011-03-30 13:58:27 +09:00
parent 23bc6f6438
commit 2a57e2e52b
4 changed files with 20 additions and 15 deletions

View File

@ -38,10 +38,10 @@ public class Snappy
int uLen = uncompressed.remaining();
int compressedSize = SnappyNative.rawCompress(uncompressed, uPos, uLen, compressed, compressed.position());
// pos limit
// [ ....XXXXXX.........]
uncompressed.limit(uncompressed.capacity());
uncompressed.position(uPos + uLen);
// // pos limit
// // [ ....XXXXXX.........]
// uncompressed.limit(uncompressed.capacity());
// uncompressed.position(uPos + uLen);
// pos limit
// [ ......BBBBBBB.........]
@ -69,8 +69,8 @@ public class Snappy
boolean ret = SnappyNative.rawDecompress(compressed, cPos, cLen, decompressed, decompressed.position());
compressed.limit(compressed.capacity());
compressed.position(cPos + cLen);
// compressed.limit(compressed.capacity());
// compressed.position(cPos + cLen);
return ret;
}

View File

@ -62,11 +62,8 @@ JNIEXPORT jint JNICALL Java_org_xerial_snappy_SnappyNative_maxCompressedLength
JNIEXPORT jint JNICALL Java_org_xerial_snappy_SnappyNative_getUncompressedLength
(JNIEnv * env, jclass self, jobject compressed, jint cpos, jint clen)
{
char* compressedBuffer = (char*) env->GetDirectBufferAddress(compressed);
if(compressedBuffer == 0)
return (jint) -1;
compressedBuffer += cpos;
char* compressedBuffer = (char*) env->GetDirectBufferAddress(compressed) + cpos;
size_t result;
snappy::GetUncompressedLength(compressedBuffer, (size_t) clen, &result);
return (jint) result;
}

View File

@ -55,11 +55,19 @@ public class SnappyTest
int maxCompressedLen = Snappy.getMaxCompressedLength(src.remaining());
_logger.info("max compressed length:" + maxCompressedLen);
int uncompressedLen = Snappy.getUncompressedLength(src);
ByteBuffer compressed = ByteBuffer.allocateDirect(1024);
int compressedSize = Snappy.compress(src, compressed);
_logger.info("compressed size: " + compressedSize);
int uncompressedLen = Snappy.getUncompressedLength(compressed);
_logger.info("uncompressed length: " + uncompressedLen);
ByteBuffer extract = ByteBuffer.allocateDirect(1024);
Snappy.decompress(compressed, extract);
extract.limit(uncompressedLen);
ByteBuffer dest = ByteBuffer.allocateDirect(1024);
Snappy.compress(src, dest);
byte[] b = new byte[uncompressedLen];
extract.get(b);
String decompressed = new String(b);
_logger.info(decompressed);
}
}