mirror of
https://github.com/xerial/snappy-java.git
synced 2025-07-05 13:14:28 +02:00
adjust buffer size
This commit is contained in:
parent
165168f1cb
commit
fa2fcabc43
@ -48,20 +48,26 @@ public class SnappyTest
|
||||
@Test
|
||||
public void load() throws Exception {
|
||||
|
||||
ByteBuffer src = ByteBuffer.allocateDirect(1024);
|
||||
src.put("hello world".getBytes());
|
||||
|
||||
StringBuilder s = new StringBuilder();
|
||||
for (int i = 0; i < 20; ++i) {
|
||||
s.append("Hello world!");
|
||||
}
|
||||
byte[] orig = s.toString().getBytes();
|
||||
int BUFFER_SIZE = orig.length;
|
||||
ByteBuffer src = ByteBuffer.allocateDirect(orig.length * 2);
|
||||
src.put(orig);
|
||||
src.flip();
|
||||
_logger.info("input size: " + src.remaining());
|
||||
int maxCompressedLen = Snappy.getMaxCompressedLength(src.remaining());
|
||||
_logger.info("max compressed length:" + maxCompressedLen);
|
||||
|
||||
ByteBuffer compressed = ByteBuffer.allocateDirect(1024);
|
||||
ByteBuffer compressed = ByteBuffer.allocateDirect(maxCompressedLen);
|
||||
int compressedSize = Snappy.compress(src, compressed);
|
||||
_logger.info("compressed size: " + compressedSize);
|
||||
_logger.info("compressed length: " + compressedSize);
|
||||
|
||||
int uncompressedLen = Snappy.getUncompressedLength(compressed);
|
||||
_logger.info("uncompressed length: " + uncompressedLen);
|
||||
ByteBuffer extract = ByteBuffer.allocateDirect(1024);
|
||||
ByteBuffer extract = ByteBuffer.allocateDirect(uncompressedLen);
|
||||
Snappy.decompress(compressed, extract);
|
||||
extract.limit(uncompressedLen);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user