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
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.
- Author:
- Tatu Saloranta, Cédrik Lime
- 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
-
Fields inherited from class java.io.FilterOutputStream
out
-
-
Constructor Summary
Constructors Modifier Constructor Description PLZFOutputStream(OutputStream outputStream)
protected
PLZFOutputStream(OutputStream outputStream, int nThreads)
protected
PLZFOutputStream(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()
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(InputStream in)
int
write(ByteBuffer src)
void
write(FileChannel in)
protected void
writeCompressedBlock()
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 IOException
WARNING: using this method will lead to very poor performance!- Overrides:
write
in classFilterOutputStream
- Throws:
IOException
-
write
public void write(byte[] buffer, int offset, int length) throws IOException
- Overrides:
write
in 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:
write
in interfaceWritableByteChannel
- Throws:
IOException
-
flush
public void flush() throws IOException
Thisflush
method does nothing.- Specified by:
flush
in interfaceFlushable
- Overrides:
flush
in classFilterOutputStream
- Throws:
IOException
-
close
public void close() throws IOException
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceChannel
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classFilterOutputStream
- Throws:
IOException
-
getUnderlyingOutputStream
public 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 IOException
Compress 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
-
-