@@ -21,21 +21,23 @@ public class Lz4OutputStream extends AbstractByteArrayOutputStream {
21
21
22
22
@ Override
23
23
protected void flushBuffer () throws IOException {
24
- int compressed = compressor .compress (buffer , 0 , position , compressedBlock , 25 );
24
+ byte [] block = compressedBlock ;
25
+ block [16 ] = Lz4InputStream .MAGIC ;
26
+ int compressed = compressor .compress (buffer , 0 , position , block , 25 );
25
27
int compressedSizeWithHeader = compressed + 9 ;
26
- BinaryStreamUtils .setInt32 (compressedBlock , 17 , compressedSizeWithHeader ); // compressed size with header
27
- BinaryStreamUtils .setInt32 (compressedBlock , 21 , position ); // uncompressed size
28
- long [] hash = ClickHouseCityHash .cityHash128 (compressedBlock , 16 , compressedSizeWithHeader );
29
- BinaryStreamUtils .setInt64 (compressedBlock , 0 , hash [0 ]);
30
- BinaryStreamUtils .setInt64 (compressedBlock , 8 , hash [1 ]);
31
- output .write (compressedBlock , 0 , compressed + 25 );
28
+ BinaryStreamUtils .setInt32 (block , 17 , compressedSizeWithHeader ); // compressed size with header
29
+ BinaryStreamUtils .setInt32 (block , 21 , position ); // uncompressed size
30
+ long [] hash = ClickHouseCityHash .cityHash128 (block , 16 , compressedSizeWithHeader );
31
+ BinaryStreamUtils .setInt64 (block , 0 , hash [0 ]);
32
+ BinaryStreamUtils .setInt64 (block , 8 , hash [1 ]);
33
+ output .write (block , 0 , compressed + 25 );
32
34
position = 0 ;
33
35
}
34
36
35
37
@ Override
36
38
protected void flushBuffer (byte [] bytes , int offset , int length ) throws IOException {
37
39
int maxLen = compressor .maxCompressedLength (length ) + 15 ;
38
- byte [] block = maxLen < compressedBlock .length ? compressedBlock : new byte [maxLen ];
40
+ byte [] block = maxLen <= compressedBlock .length ? compressedBlock : new byte [maxLen ];
39
41
block [16 ] = Lz4InputStream .MAGIC ;
40
42
41
43
int compressed = compressor .compress (bytes , offset , length , block , 25 );
@@ -61,7 +63,6 @@ public Lz4OutputStream(ClickHouseFile file, OutputStream stream, int maxCompress
61
63
compressor = factory .fastCompressor ();
62
64
// reserve the first 9 bytes for calculating checksum
63
65
compressedBlock = new byte [compressor .maxCompressedLength (maxCompressBlockSize ) + 15 ];
64
- compressedBlock [16 ] = Lz4InputStream .MAGIC ;
65
66
}
66
67
67
68
@ Override
0 commit comments