Package org.elasticsearch.transport
Class ReuseBuffersLZ4BlockOutputStream
java.lang.Object
java.io.OutputStream
java.io.FilterOutputStream
org.elasticsearch.transport.ReuseBuffersLZ4BlockOutputStream
- All Implemented Interfaces:
Closeable
,Flushable
,AutoCloseable
This file is forked from https://github.com/lz4/lz4-java. In particular it forks the following file
net.jpountz.lz4.LZ4BlockOutputStream.
It modifies the original lz4-java code to allow the reuse of local thread local byte arrays. This prevents
the need to allocate two new byte arrays everytime a new stream is created. For the Elasticsearch use case,
a single thread should fully compress the stream in one go to avoid memory corruption.
Streaming LZ4 (not compatible with the LZ4 Frame format).
This class compresses data into fixed-size blocks of compressed data.
This class uses its own format and is not compatible with the LZ4 Frame format.
For interoperability with other LZ4 tools, use
LZ4FrameOutputStream
,
which is compatible with the LZ4 Frame format. This class remains for backward compatibility.- See Also:
LZ4BlockInputStream
,LZ4FrameOutputStream
-
Field Summary
Fields inherited from class java.io.FilterOutputStream
out
-
Constructor Summary
ConstructorDescriptionCreates a new instance which compresses into blocks of 64 KB.ReuseBuffersLZ4BlockOutputStream(OutputStream out, int blockSize)
Creates a new instance which compresses with the standard LZ4 compression algorithm.ReuseBuffersLZ4BlockOutputStream(OutputStream out, int blockSize, net.jpountz.lz4.LZ4Compressor compressor)
Creates a new instance which checks stream integrity usingStreamingXXHash32
and doesn't sync flush.ReuseBuffersLZ4BlockOutputStream(OutputStream out, int blockSize, net.jpountz.lz4.LZ4Compressor compressor, Checksum checksum, boolean syncFlush)
Creates a newOutputStream
with configurable block size. -
Method Summary
Methods inherited from class java.io.OutputStream
nullOutputStream
-
Constructor Details
-
ReuseBuffersLZ4BlockOutputStream
public ReuseBuffersLZ4BlockOutputStream(OutputStream out, int blockSize, net.jpountz.lz4.LZ4Compressor compressor, Checksum checksum, boolean syncFlush)Creates a newOutputStream
with configurable block size. Large blocks require more memory at compression and decompression time but should improve the compression ratio.- Parameters:
out
- theOutputStream
to feedblockSize
- the maximum number of bytes to try to compress at once, must be >= 64 and <= 32 Mcompressor
- theLZ4Compressor
instance to use to compress datachecksum
- theChecksum
instance to use to check data for integrity.syncFlush
- true if pending data should also be flushed onflush()
-
ReuseBuffersLZ4BlockOutputStream
public ReuseBuffersLZ4BlockOutputStream(OutputStream out, int blockSize, net.jpountz.lz4.LZ4Compressor compressor)Creates a new instance which checks stream integrity usingStreamingXXHash32
and doesn't sync flush.- Parameters:
out
- theOutputStream
to feedblockSize
- the maximum number of bytes to try to compress at once, must be >= 64 and <= 32 Mcompressor
- theLZ4Compressor
instance to use to compress data- See Also:
ReuseBuffersLZ4BlockOutputStream(OutputStream, int, LZ4Compressor, Checksum, boolean)
,StreamingXXHash32.asChecksum()
-
ReuseBuffersLZ4BlockOutputStream
Creates a new instance which compresses with the standard LZ4 compression algorithm.- Parameters:
out
- theOutputStream
to feedblockSize
- the maximum number of bytes to try to compress at once, must be >= 64 and <= 32 M- See Also:
ReuseBuffersLZ4BlockOutputStream(OutputStream, int, LZ4Compressor)
,LZ4Factory.fastCompressor()
-
ReuseBuffersLZ4BlockOutputStream
Creates a new instance which compresses into blocks of 64 KB.- Parameters:
out
- theOutputStream
to feed- See Also:
ReuseBuffersLZ4BlockOutputStream(OutputStream, int)
-
-
Method Details
-
write
- Overrides:
write
in classFilterOutputStream
- Throws:
IOException
-
write
- Overrides:
write
in classFilterOutputStream
- Throws:
IOException
-
write
- Overrides:
write
in classFilterOutputStream
- Throws:
IOException
-
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classFilterOutputStream
- Throws:
IOException
-
flush
Flushes this compressedOutputStream
. If the stream has been created withsyncFlush=true
, pending data will be compressed and appended to the underlyingOutputStream
before 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:
flush
in interfaceFlushable
- Overrides:
flush
in 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
-