Package com.ning.compress.lzf.parallel
Class PLZFOutputStream
- java.lang.Object
-
- java.io.OutputStream
-
- java.io.FilterOutputStream
-
- com.ning.compress.lzf.parallel.PLZFOutputStream
-
- All Implemented Interfaces:
Closeable,Flushable,AutoCloseable,Channel,WritableByteChannel
public class PLZFOutputStream 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.This class uses a parallel implementation to make use of all available cores, modulo system load.
- Author:
- Tatu Saloranta, Cédrik Lime
- See Also:
LZFInputStream,LZFCompressingInputStream,LZFOutputStream
-
-
Field Summary
Fields Modifier and Type Field Description 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 Modifier Constructor Description PLZFOutputStream(OutputStream outputStream)protectedPLZFOutputStream(OutputStream outputStream, int nThreads)protectedPLZFOutputStream(OutputStream outputStream, int bufferSize, int nThreads)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidcheckNotClosed()protected voidcheckWriteException()voidclose()voidflush()Thisflushmethod does nothing.protected static intgetNThreads()OutputStreamgetUnderlyingOutputStream()Method that can be used to find underlyingOutputStreamthat we write encoded LZF encoded data into, after compressing it.booleanisOpen()voidwrite(byte[] buffer, int offset, int length)voidwrite(int singleByte)WARNING: using this method will lead to very poor performance!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
-
-
-
-
Constructor Detail
-
PLZFOutputStream
public PLZFOutputStream(OutputStream outputStream)
-
PLZFOutputStream
protected PLZFOutputStream(OutputStream outputStream, int nThreads)
-
PLZFOutputStream
protected PLZFOutputStream(OutputStream outputStream, int bufferSize, int nThreads)
-
-
Method Detail
-
getNThreads
protected static int getNThreads()
-
write
public void write(int singleByte) throws IOExceptionWARNING: using this method will lead to very poor performance!- 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 IOExceptionThisflushmethod does nothing.- 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).
-
writeCompressedBlock
protected void writeCompressedBlock() throws IOExceptionCompress and write the current block to the OutputStream- Throws:
IOException
-
checkWriteException
protected void checkWriteException() throws IOException- Throws:
IOException
-
checkNotClosed
protected void checkNotClosed() throws IOException- Throws:
IOException
-
-