Top Description Fields Constructors Methods
com.ning.compress.lzf

public Class LZFOutputStream

extends FilterOutputStream
implements WritableByteChannel
Class Inheritance
All Implemented Interfaces
java.nio.channels.WritableByteChannel, java.nio.channels.Channel, java.io.Closeable, java.lang.AutoCloseable
Imports
java.io.FilterOutputStream, .IOException, .InputStream, .OutputStream, java.nio.ByteBuffer, .MappedByteBuffer, java.nio.channels.FileChannel, .FileChannel.MapMode, .WritableByteChannel, com.ning.compress.BufferRecycler, com.ning.compress.lzf.util.ChunkEncoderFactory

Decorator OutputStream implementation that will compress output using LZF compression algorithm, given uncompressed input to write. Its counterpart is LZFInputStream; although in some ways LZFCompressingInputStream can be seen as the opposite.
Authors
jon hartlaub, Tatu Saloranta
See Also
LZFInputStream, LZFCompressingInputStream

Field Summary

Modifier and TypeField and Description
protected boolean
_cfgFinishBlockOnFlush

Configuration setting that governs whether basic 'flush()' should first complete a block or not.

private final ChunkEncoder
protected byte[]
protected boolean
_outputStreamClosed

Flag that indicates if we have already called '_outputStream.close()' (to avoid calling it multiple times)

protected int
private final BufferRecycler
private static final int
Inherited from java.io.FilterOutputStream:
out

Constructor Summary

AccessConstructor and Description
public
LZFOutputStream(final OutputStream outputStream)

public
LZFOutputStream(final ChunkEncoder encoder, final OutputStream outputStream)

public
LZFOutputStream(final OutputStream outputStream, final BufferRecycler bufferRecycler)

public
LZFOutputStream(final ChunkEncoder encoder, final OutputStream outputStream, final BufferRecycler bufferRecycler)

public
LZFOutputStream(final ChunkEncoder encoder, final OutputStream outputStream, final int bufferSize, BufferRecycler bufferRecycler)

Method Summary

Modifier and TypeMethod and Description
protected void
public void
public LZFOutputStream
finishBlock()

Method that can be used to force completion of the current block, which means that all buffered data will be compressed into an LZF block.

public void
flush()

Overrides java.io.FilterOutputStream.flush.

Implements java.io.Flushable.flush.

Flushes this output stream and forces any buffered output bytes to be written out to the stream.
public boolean
getFinishBlockOnFlush()

Accessor for checking whether call to "flush()" will first finish the current block or not.

public OutputStream
getUnderlyingOutputStream()

Method that can be used to find underlying OutputStream that we write encoded LZF encoded data into, after compressing it.

public boolean
isOpen()

Implements java.nio.channels.Channel.isOpen.

Tells whether or not this channel is open.
public LZFOutputStream
setFinishBlockOnFlush(boolean b)

Method for defining whether call to flush will also complete current block (similar to calling finishBlock()) or not.

public void
write(final int
the byte.
singleByte
)

Overrides java.io.FilterOutputStream.write.

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

Overrides java.io.FilterOutputStream.write.

Writes len bytes from the specified byte array starting at offset off to this output stream.
public void
write(final InputStream in)

public void
write(final FileChannel in)

public synchronized int
write(final ByteBuffer
The buffer from which bytes are to be retrieved
src
)

Implements java.nio.channels.WritableByteChannel.write.

Writes a sequence of bytes to this channel from the given buffer.
protected void
writeCompressedBlock()

Compress and write the current block to the OutputStream

Inherited from java.io.FilterOutputStream:
write

Field Detail

_cfgFinishBlockOnFlushback to summary
protected boolean _cfgFinishBlockOnFlush

Configuration setting that governs whether basic 'flush()' should first complete a block or not.

Default value is 'true'

_encoderback to summary
private final ChunkEncoder _encoder
_outputBufferback to summary
protected byte[] _outputBuffer
_outputStreamClosedback to summary
protected boolean _outputStreamClosed

Flag that indicates if we have already called '_outputStream.close()' (to avoid calling it multiple times)

_positionback to summary
protected int _position
_recyclerback to summary
private final BufferRecycler _recycler
DEFAULT_OUTPUT_BUFFER_SIZEback to summary
private static final int DEFAULT_OUTPUT_BUFFER_SIZE

Constructor Detail

LZFOutputStreamback to summary
public LZFOutputStream(final OutputStream outputStream)
LZFOutputStreamback to summary
public LZFOutputStream(final ChunkEncoder encoder, final OutputStream outputStream)
LZFOutputStreamback to summary
public LZFOutputStream(final OutputStream outputStream, final BufferRecycler bufferRecycler)
LZFOutputStreamback to summary
public LZFOutputStream(final ChunkEncoder encoder, final OutputStream outputStream, final BufferRecycler bufferRecycler)
LZFOutputStreamback to summary
public LZFOutputStream(final ChunkEncoder encoder, final OutputStream outputStream, final int bufferSize, BufferRecycler bufferRecycler)

Method Detail

checkNotClosedback to summary
protected void checkNotClosed() throws IOException
closeback to summary
public void close() throws IOException

Overrides java.io.FilterOutputStream.close.

Implements java.nio.channels.Channel.close, java.io.Closeable.close.

Doc from java.nio.channels.Channel.close.

Closes this channel.

After a channel is closed, any further attempt to invoke I/O operations upon it will cause a ClosedChannelException to be thrown.

If this channel is already closed then invoking this method has no effect.

This method may be invoked at any time. If some other thread has already invoked it, however, then another invocation will block until the first invocation is complete, after which it will return without effect.

Annotations
@Override
Exceptions
IOException:
If an I/O error occurs
finishBlockback to summary
public LZFOutputStream finishBlock() throws IOException

Method that can be used to force completion of the current block, which means that all buffered data will be compressed into an LZF block. This typically results in lower compression ratio as larger blocks compress better; but may be necessary for network connections to ensure timely sending of data.

flushback to summary
public void flush() throws IOException

Overrides java.io.FilterOutputStream.flush.

Implements java.io.Flushable.flush.

Doc from java.io.FilterOutputStream.flush.

Flushes this output stream and forces any buffered output bytes to be written out to the stream.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs.
getFinishBlockOnFlushback to summary
public boolean getFinishBlockOnFlush()

Accessor for checking whether call to "flush()" will first finish the current block or not.

getUnderlyingOutputStreamback to summary
public OutputStream getUnderlyingOutputStream()

Method that can be used to find underlying OutputStream that we write encoded LZF encoded data into, after compressing it. Will never return null; although underlying stream may be closed (if this stream has been closed).

isOpenback to summary
public boolean isOpen()

Implements java.nio.channels.Channel.isOpen.

Doc from java.nio.channels.Channel.isOpen.

Tells whether or not this channel is open.

Returns:boolean

true if, and only if, this channel is open

Annotations
@Override
setFinishBlockOnFlushback to summary
public LZFOutputStream setFinishBlockOnFlush(boolean b)

Method for defining whether call to flush will also complete current block (similar to calling finishBlock()) or not.

writeback to summary
public void write(final int singleByte) 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
singleByte:int

the byte.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs.
writeback to summary
public void write(final byte[] buffer, int offset, int length) 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
buffer:byte[]

the data.

offset:int

the start offset in the data.

length:int

the number of bytes to write.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs.
writeback to summary
public void write(final InputStream in) throws IOException
writeback to summary
public void write(final FileChannel in) throws IOException
writeback to summary
public synchronized int write(final ByteBuffer src) throws IOException

Implements java.nio.channels.WritableByteChannel.write.

Doc from java.nio.channels.WritableByteChannel.write.

Writes a sequence of bytes to this channel from the given buffer.

An attempt is made to write up to r bytes to the channel, where r is the number of bytes remaining in the buffer, that is, src.remaining(), at the moment this method is invoked.

Suppose that a byte sequence of length n is written, where 0 <= n <= r. This byte sequence will be transferred from the buffer starting at index p, where p is the buffer's position at the moment this method is invoked; the index of the last byte written will be p + n - 1. Upon return the buffer's position will be equal to p + n; its limit will not have changed.

Unless otherwise specified, a write operation will return only after writing all of the r requested bytes. Some types of channels, depending upon their state, may write only some of the bytes or possibly none at all. A socket channel in non-blocking mode, for example, cannot write any more bytes than are free in the socket's output buffer.

This method may be invoked at any time. If another thread has already initiated a write operation upon this channel, however, then an invocation of this method will block until the first operation is complete.

Parameters
src:ByteBuffer

The buffer from which bytes are to be retrieved

Returns:int

The number of bytes written, possibly zero

Annotations
@Override
Exceptions
IOException:
If some other I/O error occurs
writeCompressedBlockback to summary
protected void writeCompressedBlock() throws IOException

Compress and write the current block to the OutputStream