Top Description Fields Constructors Methods
net.jpountz.lz4

public final Class LZ4BlockOutputStream

extends FilterOutputStream
Class Inheritance
Imports
java.io.FilterOutputStream, .IOException, .OutputStream, java.util.zip.Checksum, net.jpountz.util.SafeUtils, net.jpountz.xxhash.StreamingXXHash32, .XXHashFactory

Streaming LZ4.

This class compresses data into fixed-size blocks of compressed data.

See Also
LZ4BlockInputStream

Field Summary

Modifier and TypeField and Description
private final int
private final byte[]
private final Checksum
private final byte[]
pack-priv static final int
pack-priv static final int
pack-priv static final int
private final int
private final LZ4Compressor
pack-priv static final int
private boolean
pack-priv static final int
pack-priv static final byte[]
pack-priv static final int
pack-priv static final int
pack-priv static final int
private int
o

private final boolean
Inherited from java.io.FilterOutputStream:
out

Constructor Summary

AccessConstructor and Description
public
LZ4BlockOutputStream(OutputStream
the OutputStream to feed
out
,
int
the maximum number of bytes to try to compress at once, must be >= 64 and <= 32 M
blockSize
,
LZ4Compressor
the LZ4Compressor instance to use to compress data
compressor
,
Checksum
the Checksum instance to use to check data for integrity.
checksum
,
boolean
true if pending data should also be flushed on flush()
syncFlush
)

Create a new OutputStream with configurable block size.

public
LZ4BlockOutputStream(OutputStream out, int blockSize, LZ4Compressor compressor)

Create a new instance which checks stream integrity using StreamingXXHash32 and doesn't sync flush.

public
LZ4BlockOutputStream(OutputStream out, int blockSize)

Create a new instance which compresses with the standard LZ4 compression algorithm.

public
LZ4BlockOutputStream(OutputStream out)

Create a new instance which compresses into blocks of 64 KB.

Method Summary

Modifier and TypeMethod and Description
public void
close()

Overrides java.io.FilterOutputStream.close.

Implements java.io.Closeable.close.

Closes this output stream and releases any system resources associated with the stream.
private static int
compressionLevel(int blockSize)

private void
public void
finish()

Same as close() except that it doesn't close the underlying stream.

public void
flush()

Overrides java.io.FilterOutputStream.flush.

Implements java.io.Flushable.flush.

Flush this compressed OutputStream.
private void
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
public void
write(int
the byte.
b
)

Overrides java.io.FilterOutputStream.write.

Writes the specified byte to this output stream.
public void
write(byte[]
the data.
b
,
int
the start offset in the data.
off
,
int
the number of bytes to write.
len
)

Overrides java.io.FilterOutputStream.write.

Writes len bytes from the specified byte array starting at offset off to this output stream.
public void
write(byte[]
the data to be written.
b
)

Overrides java.io.FilterOutputStream.write.

Writes b.length bytes to this output stream.
private static void
writeIntLE(int i, byte[] buf, int off)

Field Detail

blockSizeback to summary
private final int blockSize
bufferback to summary
private final byte[] buffer
checksumback to summary
private final Checksum checksum
compressedBufferback to summary
private final byte[] compressedBuffer
COMPRESSION_LEVEL_BASEback to summary
pack-priv static final int COMPRESSION_LEVEL_BASE
COMPRESSION_METHOD_LZ4back to summary
pack-priv static final int COMPRESSION_METHOD_LZ4
COMPRESSION_METHOD_RAWback to summary
pack-priv static final int COMPRESSION_METHOD_RAW
compressionLevelback to summary
private final int compressionLevel
compressorback to summary
private final LZ4Compressor compressor
DEFAULT_SEEDback to summary
pack-priv static final int DEFAULT_SEED
finishedback to summary
private boolean finished
HEADER_LENGTHback to summary
pack-priv static final int HEADER_LENGTH
MAGICback to summary
pack-priv static final byte[] MAGIC
MAGIC_LENGTHback to summary
pack-priv static final int MAGIC_LENGTH
MAX_BLOCK_SIZEback to summary
pack-priv static final int MAX_BLOCK_SIZE
MIN_BLOCK_SIZEback to summary
pack-priv static final int MIN_BLOCK_SIZE
oback to summary
private int o
syncFlushback to summary
private final boolean syncFlush

Constructor Detail

LZ4BlockOutputStreamback to summary
public LZ4BlockOutputStream(OutputStream out, int blockSize, LZ4Compressor compressor, Checksum checksum, boolean syncFlush)

Create a new OutputStream with configurable block size. Large blocks require more memory at compression and decompression time but should improve the compression ratio.

Parameters
out:OutputStream

the OutputStream to feed

blockSize:int

the maximum number of bytes to try to compress at once, must be >= 64 and <= 32 M

compressor:LZ4Compressor

the LZ4Compressor instance to use to compress data

checksum:Checksum

the Checksum instance to use to check data for integrity.

syncFlush:boolean

true if pending data should also be flushed on flush()

LZ4BlockOutputStreamback to summary
public LZ4BlockOutputStream(OutputStream out, int blockSize, LZ4Compressor compressor)

Create a new instance which checks stream integrity using StreamingXXHash32 and doesn't sync flush.

See Also
LZ4BlockOutputStream(OutputStream, int, LZ4Compressor, Checksum, boolean), StreamingXXHash32#asChecksum()
LZ4BlockOutputStreamback to summary
public LZ4BlockOutputStream(OutputStream out, int blockSize)

Create a new instance which compresses with the standard LZ4 compression algorithm.

See Also
LZ4BlockOutputStream(OutputStream, int, LZ4Compressor), LZ4Factory#fastCompressor()
LZ4BlockOutputStreamback to summary
public LZ4BlockOutputStream(OutputStream out)

Create a new instance which compresses into blocks of 64 KB.

See Also
LZ4BlockOutputStream(OutputStream, int)

Method Detail

closeback to summary
public void close() throws IOException

Overrides java.io.FilterOutputStream.close.

Implements java.io.Closeable.close.

Doc from java.io.FilterOutputStream.close.

Closes this output stream and releases any system resources associated with the stream.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs.
compressionLevelback to summary
private static int compressionLevel(int blockSize)
ensureNotFinishedback to summary
private void ensureNotFinished()
finishback to summary
public void finish() throws IOException

Same as close() except that it doesn't close the underlying stream. This can be useful if you want to keep on using the underlying stream.

flushback to summary
public void flush() throws IOException

Overrides java.io.FilterOutputStream.flush.

Implements java.io.Flushable.flush.

Flush this compressed OutputStream. If the stream has been created with syncFlush=true, pending data will be compressed and appended to the underlying OutputStream before calling OutputStream#flush() on the underlying stream. Otherwise, this method just flushes the underlying stream, so pending data might not be available for reading until finish() or close() is called.

Annotations
@Override
Exceptions
IOException:

Doc from java.io.FilterOutputStream.flush.

if an I/O error occurs.

flushBufferedDataback to summary
private void flushBufferedData() throws IOException
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override
writeback to summary
public void write(int b) throws IOException

Overrides java.io.FilterOutputStream.write.

Doc from java.io.FilterOutputStream.write.

Writes the specified byte to this output stream.

The write method of FilterOutputStream calls the write method of its underlying output stream, that is, it performs out.write(b).

Implements the abstract write method of OutputStream.

Parameters
b:int

the byte.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs.
writeback to summary
public void write(byte[] b, int off, int len) throws IOException

Overrides java.io.FilterOutputStream.write.

Doc from java.io.FilterOutputStream.write.

Writes len bytes from the specified byte array starting at offset off to this output stream.

Parameters
b:byte[]

the data.

off:int

the start offset in the data.

len:int

the number of bytes to write.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs.
writeback to summary
public void write(byte[] b) throws IOException

Overrides java.io.FilterOutputStream.write.

Doc from java.io.FilterOutputStream.write.

Writes b.length bytes to this output stream.

Parameters
b:byte[]

the data to be written.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs.
writeIntLEback to summary
private static void writeIntLE(int i, byte[] buf, int off)