From fa2fcabc4300d510bc5b9b3d53330841a4551cd5 Mon Sep 17 00:00:00 2001 From: "Taro L. Saito" Date: Wed, 30 Mar 2011 14:05:23 +0900 Subject: [PATCH] adjust buffer size --- .../java/org/xerial/snappy/SnappyTest.java | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/test/java/org/xerial/snappy/SnappyTest.java b/src/test/java/org/xerial/snappy/SnappyTest.java index b0d2f8e..2dddd1a 100755 --- a/src/test/java/org/xerial/snappy/SnappyTest.java +++ b/src/test/java/org/xerial/snappy/SnappyTest.java @@ -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);