@@ -48,20 +48,26 @@ public void directBufferCheck() throws Exception {
48
48
@ Test
49
49
public void load () throws Exception {
50
50
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 );
54
59
src .flip ();
60
+ _logger .info ("input size: " + src .remaining ());
55
61
int maxCompressedLen = Snappy .getMaxCompressedLength (src .remaining ());
56
62
_logger .info ("max compressed length:" + maxCompressedLen );
57
63
58
- ByteBuffer compressed = ByteBuffer .allocateDirect (1024 );
64
+ ByteBuffer compressed = ByteBuffer .allocateDirect (maxCompressedLen );
59
65
int compressedSize = Snappy .compress (src , compressed );
60
- _logger .info ("compressed size : " + compressedSize );
66
+ _logger .info ("compressed length : " + compressedSize );
61
67
62
68
int uncompressedLen = Snappy .getUncompressedLength (compressed );
63
69
_logger .info ("uncompressed length: " + uncompressedLen );
64
- ByteBuffer extract = ByteBuffer .allocateDirect (1024 );
70
+ ByteBuffer extract = ByteBuffer .allocateDirect (uncompressedLen );
65
71
Snappy .decompress (compressed , extract );
66
72
extract .limit (uncompressedLen );
67
73
0 commit comments