Skip to content

Commit fa2fcab

Browse files
committed
adjust buffer size
1 parent 165168f commit fa2fcab

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/test/java/org/xerial/snappy/SnappyTest.java

+12-6
Original file line numberDiff line numberDiff line change
@@ -48,20 +48,26 @@ public void directBufferCheck() throws Exception {
4848
@Test
4949
public void load() throws Exception {
5050

51-
ByteBuffer src = ByteBuffer.allocateDirect(1024);
52-
src.put("hello world".getBytes());
53-
51+
StringBuilder s = new StringBuilder();
52+
for (int i = 0; i < 20; ++i) {
53+
s.append("Hello world!");
54+
}
55+
byte[] orig = s.toString().getBytes();
56+
int BUFFER_SIZE = orig.length;
57+
ByteBuffer src = ByteBuffer.allocateDirect(orig.length * 2);
58+
src.put(orig);
5459
src.flip();
60+
_logger.info("input size: " + src.remaining());
5561
int maxCompressedLen = Snappy.getMaxCompressedLength(src.remaining());
5662
_logger.info("max compressed length:" + maxCompressedLen);
5763

58-
ByteBuffer compressed = ByteBuffer.allocateDirect(1024);
64+
ByteBuffer compressed = ByteBuffer.allocateDirect(maxCompressedLen);
5965
int compressedSize = Snappy.compress(src, compressed);
60-
_logger.info("compressed size: " + compressedSize);
66+
_logger.info("compressed length: " + compressedSize);
6167

6268
int uncompressedLen = Snappy.getUncompressedLength(compressed);
6369
_logger.info("uncompressed length: " + uncompressedLen);
64-
ByteBuffer extract = ByteBuffer.allocateDirect(1024);
70+
ByteBuffer extract = ByteBuffer.allocateDirect(uncompressedLen);
6571
Snappy.decompress(compressed, extract);
6672
extract.limit(uncompressedLen);
6773

0 commit comments

Comments
 (0)