Package com.ning.compress.lzf
Class LZFOutputStream
- java.lang.Object
-
- java.io.OutputStream
-
- java.io.FilterOutputStream
-
- com.ning.compress.lzf.LZFOutputStream
-
- All Implemented Interfaces:
Closeable,Flushable,AutoCloseable,Channel,WritableByteChannel
public class LZFOutputStream extends FilterOutputStream implements WritableByteChannel
DecoratorOutputStreamimplementation that will compress output using LZF compression algorithm, given uncompressed input to write. Its counterpart isLZFInputStream; although in some waysLZFCompressingInputStreamcan be seen as the opposite.- Author:
- jon hartlaub, Tatu Saloranta
- See Also:
LZFInputStream,LZFCompressingInputStream
-
-
Field Summary
Fields Modifier and Type Field Description protected boolean_cfgFinishBlockOnFlushConfiguration setting that governs whether basic 'flush()' should first complete a block or not.protected byte[]_outputBufferprotected boolean_outputStreamClosedFlag that indicates if we have already called '_outputStream.close()' (to avoid calling it multiple times)protected int_position-
Fields inherited from class java.io.FilterOutputStream
out
-
-
Constructor Summary
Constructors Constructor Description LZFOutputStream(ChunkEncoder encoder, OutputStream outputStream)LZFOutputStream(ChunkEncoder encoder, OutputStream outputStream, int bufferSize, BufferRecycler bufferRecycler)LZFOutputStream(ChunkEncoder encoder, OutputStream outputStream, BufferRecycler bufferRecycler)LZFOutputStream(OutputStream outputStream)LZFOutputStream(OutputStream outputStream, BufferRecycler bufferRecycler)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidcheckNotClosed()voidclose()LZFOutputStreamfinishBlock()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.voidflush()booleangetFinishBlockOnFlush()Accessor for checking whether call to "flush()" will first finish the current block or not.OutputStreamgetUnderlyingOutputStream()Method that can be used to find underlyingOutputStreamthat we write encoded LZF encoded data into, after compressing it.booleanisOpen()LZFOutputStreamsetFinishBlockOnFlush(boolean b)Method for defining whether call toflush()will also complete current block (similar to callingfinishBlock()) or not.voidwrite(byte[] buffer, int offset, int length)voidwrite(int singleByte)voidwrite(InputStream in)intwrite(ByteBuffer src)voidwrite(FileChannel in)protected voidwriteCompressedBlock()Compress and write the current block to the OutputStream-
Methods inherited from class java.io.FilterOutputStream
write
-
Methods inherited from class java.io.OutputStream
nullOutputStream
-
-
-
-
Field Detail
-
_outputBuffer
protected byte[] _outputBuffer
-
_position
protected int _position
-
_cfgFinishBlockOnFlush
protected boolean _cfgFinishBlockOnFlush
Configuration setting that governs whether basic 'flush()' should first complete a block or not.Default value is 'true'
-
_outputStreamClosed
protected boolean _outputStreamClosed
Flag that indicates if we have already called '_outputStream.close()' (to avoid calling it multiple times)
-
-
Constructor Detail
-
LZFOutputStream
public LZFOutputStream(OutputStream outputStream)
-
LZFOutputStream
public LZFOutputStream(ChunkEncoder encoder, OutputStream outputStream)
-
LZFOutputStream
public LZFOutputStream(OutputStream outputStream, BufferRecycler bufferRecycler)
-
LZFOutputStream
public LZFOutputStream(ChunkEncoder encoder, OutputStream outputStream, BufferRecycler bufferRecycler)
-
LZFOutputStream
public LZFOutputStream(ChunkEncoder encoder, OutputStream outputStream, int bufferSize, BufferRecycler bufferRecycler)
-
-
Method Detail
-
setFinishBlockOnFlush
public LZFOutputStream setFinishBlockOnFlush(boolean b)
Method for defining whether call toflush()will also complete current block (similar to callingfinishBlock()) or not.
-
write
public void write(int singleByte) throws IOException- Overrides:
writein classFilterOutputStream- Throws:
IOException
-
write
public void write(byte[] buffer, int offset, int length) throws IOException- Overrides:
writein classFilterOutputStream- Throws:
IOException
-
write
public void write(InputStream in) throws IOException
- Throws:
IOException
-
write
public void write(FileChannel in) throws IOException
- Throws:
IOException
-
write
public int write(ByteBuffer src) throws IOException
- Specified by:
writein interfaceWritableByteChannel- Throws:
IOException
-
flush
public void flush() throws IOException- Specified by:
flushin interfaceFlushable- Overrides:
flushin classFilterOutputStream- Throws:
IOException
-
close
public void close() throws IOException- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceChannel- Specified by:
closein interfaceCloseable- Overrides:
closein classFilterOutputStream- Throws:
IOException
-
getUnderlyingOutputStream
public OutputStream getUnderlyingOutputStream()
Method that can be used to find underlyingOutputStreamthat 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).
-
getFinishBlockOnFlush
public boolean getFinishBlockOnFlush()
Accessor for checking whether call to "flush()" will first finish the current block or not.
-
finishBlock
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.- Throws:
IOException
-
writeCompressedBlock
protected void writeCompressedBlock() throws IOExceptionCompress and write the current block to the OutputStream- Throws:
IOException
-
checkNotClosed
protected void checkNotClosed() throws IOException- Throws:
IOException
-
-