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.WritableByteChannel
DecoratorOutputStream
implementation that will compress output using LZF compression algorithm, given uncompressed input to write. Its counterpart isLZFInputStream
; although in some waysLZFCompressingInputStream
can 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[]
_outputBuffer
protected boolean
_outputStreamClosed
Flag that indicates if we have already called '_outputStream.close()' (to avoid calling it multiple times)protected int
_position
private BlockManager
blockManager
private java.util.concurrent.ExecutorService
compressExecutor
private static int
DEFAULT_OUTPUT_BUFFER_SIZE
(package private) java.lang.Exception
writeException
private java.util.concurrent.ExecutorService
writeExecutor
-
Constructor Summary
Constructors Modifier Constructor Description PLZFOutputStream(java.io.OutputStream outputStream)
protected
PLZFOutputStream(java.io.OutputStream outputStream, int nThreads)
protected
PLZFOutputStream(java.io.OutputStream outputStream, int bufferSize, int nThreads)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
checkNotClosed()
protected void
checkWriteException()
void
close()
void
flush()
Thisflush
method does nothing.protected static int
getNThreads()
java.io.OutputStream
getUnderlyingOutputStream()
Method that can be used to find underlyingOutputStream
that we write encoded LZF encoded data into, after compressing it.boolean
isOpen()
void
write(byte[] buffer, int offset, int length)
void
write(int singleByte)
WARNING: using this method will lead to very poor performance!void
write(java.io.InputStream in)
int
write(java.nio.ByteBuffer src)
void
write(java.nio.channels.FileChannel in)
protected void
writeCompressedBlock()
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.IOException
WARNING: using this method will lead to very poor performance!- Overrides:
write
in classjava.io.FilterOutputStream
- Throws:
java.io.IOException
-
write
public void write(byte[] buffer, int offset, int length) throws java.io.IOException
- Overrides:
write
in 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:
write
in interfacejava.nio.channels.WritableByteChannel
- Throws:
java.io.IOException
-
flush
public void flush() throws java.io.IOException
Thisflush
method does nothing.- Specified by:
flush
in interfacejava.io.Flushable
- Overrides:
flush
in classjava.io.FilterOutputStream
- Throws:
java.io.IOException
-
isOpen
public boolean isOpen()
- Specified by:
isOpen
in interfacejava.nio.channels.Channel
-
close
public void close() throws java.io.IOException
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.nio.channels.Channel
- Specified by:
close
in interfacejava.io.Closeable
- Overrides:
close
in classjava.io.FilterOutputStream
- Throws:
java.io.IOException
-
getUnderlyingOutputStream
public java.io.OutputStream getUnderlyingOutputStream()
Method that can be used to find underlyingOutputStream
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).
-
writeCompressedBlock
protected void writeCompressedBlock() throws java.io.IOException
Compress 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
-
-