Class LZ4BlockOutputStream
- All Implemented Interfaces:
Closeable, Flushable, AutoCloseable
LZ4FrameOutputStream,
which is compatible with the LZ4 Frame format. This class remains for backward compatibility.
Each block starts with a header made of the magic bytes "LZ4Block",
a token byte, the compressed length, the decompressed length and a checksum
of the decompressed data (all three as 32-bit little-endian integers),
followed by the block data. The high nibble of the token is the compression
method (0x10 for raw, 0x20 for LZ4) and the low nibble is the
block size exponent, max(0, ceil(log2(blockSize)) - 10). When the
default checksum is used, the checksum field is the XXHash32 (seed
0x9747b28c) of the uncompressed block, masked to its low 28 bits
(see StreamingXXHash32.asChecksum()). The exception is the
end-of-stream block written by finish(), which is a raw block whose
lengths and checksum are all 0.
- See Also:
-
Field Summary
Fields inherited from class FilterOutputStream
out -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new instance which compresses into blocks of 64 KB.LZ4BlockOutputStream(OutputStream out, int blockSize) Creates a new instance which compresses with the standard LZ4 compression algorithm.LZ4BlockOutputStream(OutputStream out, int blockSize, LZ4Compressor compressor) Creates a new instance which checks stream integrity usingStreamingXXHash32and doesn't sync flush.LZ4BlockOutputStream(OutputStream out, int blockSize, LZ4Compressor compressor, Checksum checksum, boolean syncFlush) Creates a newOutputStreamwith configurable block size. -
Method Summary
Methods inherited from class OutputStream
nullOutputStream
-
Constructor Details
-
LZ4BlockOutputStream
public LZ4BlockOutputStream(OutputStream out, int blockSize, LZ4Compressor compressor, Checksum checksum, boolean syncFlush) Creates a newOutputStreamwith configurable block size. Large blocks require more memory at compression and decompression time but should improve the compression ratio.- Parameters:
out- theOutputStreamto feedblockSize- the maximum number of bytes to try to compress at once, must be >= 64 and <= 32 Mcompressor- theLZ4Compressorinstance to use to compress datachecksum- theChecksuminstance to use to check data for integrity.syncFlush- true if pending data should also be flushed onflush()
-
LZ4BlockOutputStream
Creates a new instance which checks stream integrity usingStreamingXXHash32and doesn't sync flush.- Parameters:
out- theOutputStreamto feedblockSize- the maximum number of bytes to try to compress at once, must be >= 64 and <= 32 Mcompressor- theLZ4Compressorinstance to use to compress data- See Also:
-
LZ4BlockOutputStream
Creates a new instance which compresses with the standard LZ4 compression algorithm.- Parameters:
out- theOutputStreamto feedblockSize- the maximum number of bytes to try to compress at once, must be >= 64 and <= 32 M- See Also:
-
LZ4BlockOutputStream
Creates a new instance which compresses into blocks of 64 KB.- Parameters:
out- theOutputStreamto feed- See Also:
-
-
Method Details
-
write
- Overrides:
writein classFilterOutputStream- Throws:
IOException
-
write
- Overrides:
writein classFilterOutputStream- Throws:
IOException
-
write
- Overrides:
writein classFilterOutputStream- Throws:
IOException
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classFilterOutputStream- Throws:
IOException
-
flush
Flushes this compressedOutputStream.If the stream has been created with
syncFlush=true, pending data will be compressed and appended to the underlyingOutputStreambefore callingOutputStream.flush()on the underlying stream. Otherwise, this method just flushes the underlying stream, so pending data might not be available for reading untilfinish()orclose()is called.- Specified by:
flushin interfaceFlushable- Overrides:
flushin classFilterOutputStream- Throws:
IOException
-
finish
Same asclose()except that it doesn't close the underlying stream. This can be useful if you want to keep on using the underlying stream.- Throws:
IOException- if an I/O error occurs.
-
toString
-