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:
java.io.Closeable,java.io.Flushable,java.lang.AutoCloseable,java.nio.channels.Channel,java.nio.channels.WritableByteChannel
public class PLZFOutputStream extends java.io.FilterOutputStream implements java.nio.channels.WritableByteChannelDecoratorOutputStreamimplementation 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.
- 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_positionprivate BlockManagerblockManagerprivate java.util.concurrent.ExecutorServicecompressExecutorprivate static intDEFAULT_OUTPUT_BUFFER_SIZE(package private) java.lang.ExceptionwriteExceptionprivate java.util.concurrent.ExecutorServicewriteExecutor
-
Constructor Summary
Constructors Modifier Constructor Description PLZFOutputStream(java.io.OutputStream outputStream)protectedPLZFOutputStream(java.io.OutputStream outputStream, int nThreads)protectedPLZFOutputStream(java.io.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()java.io.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(java.io.InputStream in)intwrite(java.nio.ByteBuffer src)voidwrite(java.nio.channels.FileChannel in)protected voidwriteCompressedBlock()Compress and write the current block to the OutputStream
-
-
-
Field Detail
-
DEFAULT_OUTPUT_BUFFER_SIZE
private static final int DEFAULT_OUTPUT_BUFFER_SIZE
- See Also:
- Constant Field Values
-
_outputBuffer
protected byte[] _outputBuffer
-
_position
protected int _position
-
_outputStreamClosed
protected boolean _outputStreamClosed
Flag that indicates if we have already called '_outputStream.close()' (to avoid calling it multiple times)
-
blockManager
private BlockManager blockManager
-
compressExecutor
private final java.util.concurrent.ExecutorService compressExecutor
-
writeExecutor
private final java.util.concurrent.ExecutorService writeExecutor
-
writeException
volatile java.lang.Exception writeException
-
-
Method Detail
-
getNThreads
protected static int getNThreads()
-
write
public void write(int singleByte) throws java.io.IOExceptionWARNING: using this method will lead to very poor performance!- Overrides:
writein classjava.io.FilterOutputStream- Throws:
java.io.IOException
-
write
public void write(byte[] buffer, int offset, int length) throws java.io.IOException- Overrides:
writein classjava.io.FilterOutputStream- Throws:
java.io.IOException
-
write
public void write(java.io.InputStream in) throws java.io.IOException- Throws:
java.io.IOException
-
write
public void write(java.nio.channels.FileChannel in) throws java.io.IOException- Throws:
java.io.IOException
-
write
public int write(java.nio.ByteBuffer src) throws java.io.IOException- Specified by:
writein interfacejava.nio.channels.WritableByteChannel- Throws:
java.io.IOException
-
flush
public void flush() throws java.io.IOExceptionThisflushmethod does nothing.- Specified by:
flushin interfacejava.io.Flushable- Overrides:
flushin classjava.io.FilterOutputStream- Throws:
java.io.IOException
-
isOpen
public boolean isOpen()
- Specified by:
isOpenin interfacejava.nio.channels.Channel
-
close
public void close() throws java.io.IOException- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.nio.channels.Channel- Specified by:
closein interfacejava.io.Closeable- Overrides:
closein classjava.io.FilterOutputStream- Throws:
java.io.IOException
-
getUnderlyingOutputStream
public java.io.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 java.io.IOExceptionCompress and write the current block to the OutputStream- Throws:
java.io.IOException
-
checkWriteException
protected void checkWriteException() throws java.io.IOException- Throws:
java.io.IOException
-
checkNotClosed
protected void checkNotClosed() throws java.io.IOException- Throws:
java.io.IOException
-
-