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

public Class PLZFOutputStream

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.lang.management.ManagementFactory, .OperatingSystemMXBean, java.nio.ByteBuffer, .MappedByteBuffer, java.nio.channels.FileChannel, .FileChannel.MapMode, .WritableByteChannel, java.util.ArrayList, .Collection, java.util.concurrent.ExecutorService, .Executors, .Future, .LinkedBlockingQueue, .ThreadPoolExecutor, .TimeUnit, com.ning.compress.lzf.LZFChunk

Decorator OutputStream implementation that will compress output using LZF compression algorithm, given uncompressed input to write. Its counterpart is com.ning.compress.lzf.LZFInputStream; although in some ways com.ning.compress.lzf.LZFCompressingInputStream can be seen as the opposite.

This class uses a parallel implementation to make use of all available cores, modulo system load.

Authors
Tatu Saloranta, Cédrik Lime
See Also
com.ning.compress.lzf.LZFInputStream, com.ning.compress.lzf.LZFCompressingInputStream, com.ning.compress.lzf.LZFOutputStream

Field Summary

Modifier and TypeField and Description
protected byte[]
protected boolean
_outputStreamClosed

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

protected int
private BlockManager
private final ExecutorService
private static final int
pack-priv volatile Exception
private final ExecutorService
Inherited from java.io.FilterOutputStream:
out

Constructor Summary

AccessConstructor and Description
public
PLZFOutputStream(final OutputStream outputStream)

protected
PLZFOutputStream(final OutputStream outputStream, int nThreads)

protected
PLZFOutputStream(final OutputStream outputStream, final int bufferSize, int nThreads)

Method Summary

Modifier and TypeMethod and Description
protected void
protected void
public void
public void
flush()

Overrides java.io.FilterOutputStream.flush.

Implements java.io.Flushable.flush.

This flush method does nothing.
protected static int
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 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

_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
blockManagerback to summary
private BlockManager blockManager
compressExecutorback to summary
private final ExecutorService compressExecutor
DEFAULT_OUTPUT_BUFFER_SIZEback to summary
private static final int DEFAULT_OUTPUT_BUFFER_SIZE
writeExceptionback to summary
pack-priv volatile Exception writeException
writeExecutorback to summary
private final ExecutorService writeExecutor

Constructor Detail

PLZFOutputStreamback to summary
public PLZFOutputStream(final OutputStream outputStream)
PLZFOutputStreamback to summary
protected PLZFOutputStream(final OutputStream outputStream, int nThreads)
PLZFOutputStreamback to summary
protected PLZFOutputStream(final OutputStream outputStream, final int bufferSize, int nThreads)

Method Detail

checkNotClosedback to summary
protected void checkNotClosed() throws IOException
checkWriteExceptionback to summary
protected void checkWriteException() 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
flushback to summary
public void flush() throws IOException

Overrides java.io.FilterOutputStream.flush.

Implements java.io.Flushable.flush.

This flush method does nothing.

Annotations
@Override
Exceptions
IOException:

Doc from java.io.FilterOutputStream.flush.

if an I/O error occurs.

getNThreadsback to summary
protected static int getNThreads()
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
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.

Warning

using this method will lead to very poor performance!

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