Package com.ning.compress.lzf.util
Class LZFFileOutputStream
- java.lang.Object
-
- java.io.OutputStream
-
- java.io.FileOutputStream
-
- com.ning.compress.lzf.util.LZFFileOutputStream
-
- All Implemented Interfaces:
Closeable,Flushable,AutoCloseable,Channel,WritableByteChannel
public class LZFFileOutputStream extends FileOutputStream implements WritableByteChannel
Helper class that allows use of LZF compression even if a library requires use ofFileOutputStream.Note that use of this class is not recommended unless you absolutely must use a
FileOutputStreaminstance; otherwise basicLZFOutputStream(which uses aggregation for underlying streams) is more appropriateImplementation note: much of the code is just copied from
LZFOutputStream, so care must be taken to keep implementations in sync if there are fixes.
-
-
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
-
Constructor Summary
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidcheckNotClosed()voidclose()LZFFileOutputStreamfinishBlock()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 notbooleanisOpen()protected voidrawWrite(byte[] buffer, int offset, int length)LZFFileOutputStreamsetFinishBlockOnFlush(boolean b)Method for defining whether call toflush()will also complete current block (similar to callingfinishBlock()) or not.voidwrite(byte[] b)voidwrite(byte[] buffer, int offset, int length)voidwrite(int b)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.FileOutputStream
finalize, getChannel, getFD
-
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
-
LZFFileOutputStream
public LZFFileOutputStream(File file) throws FileNotFoundException
- Throws:
FileNotFoundException
-
LZFFileOutputStream
public LZFFileOutputStream(File file, boolean append) throws FileNotFoundException
- Throws:
FileNotFoundException
-
LZFFileOutputStream
public LZFFileOutputStream(FileDescriptor fdObj)
-
LZFFileOutputStream
public LZFFileOutputStream(String name) throws FileNotFoundException
- Throws:
FileNotFoundException
-
LZFFileOutputStream
public LZFFileOutputStream(String name, boolean append) throws FileNotFoundException
- Throws:
FileNotFoundException
-
LZFFileOutputStream
public LZFFileOutputStream(ChunkEncoder encoder, File file) throws FileNotFoundException
- Throws:
FileNotFoundException
-
LZFFileOutputStream
public LZFFileOutputStream(ChunkEncoder encoder, File file, boolean append) throws FileNotFoundException
- Throws:
FileNotFoundException
-
LZFFileOutputStream
public LZFFileOutputStream(ChunkEncoder encoder, FileDescriptor fdObj)
-
LZFFileOutputStream
public LZFFileOutputStream(ChunkEncoder encoder, String name) throws FileNotFoundException
- Throws:
FileNotFoundException
-
LZFFileOutputStream
public LZFFileOutputStream(ChunkEncoder encoder, String name, boolean append) throws FileNotFoundException
- Throws:
FileNotFoundException
-
LZFFileOutputStream
public LZFFileOutputStream(ChunkEncoder encoder, File file, BufferRecycler bufferRecycler) throws FileNotFoundException
- Throws:
FileNotFoundException
-
LZFFileOutputStream
public LZFFileOutputStream(ChunkEncoder encoder, File file, boolean append, BufferRecycler bufferRecycler) throws FileNotFoundException
- Throws:
FileNotFoundException
-
LZFFileOutputStream
public LZFFileOutputStream(ChunkEncoder encoder, FileDescriptor fdObj, BufferRecycler bufferRecycler)
-
LZFFileOutputStream
public LZFFileOutputStream(ChunkEncoder encoder, String name, BufferRecycler bufferRecycler) throws FileNotFoundException
- Throws:
FileNotFoundException
-
LZFFileOutputStream
public LZFFileOutputStream(ChunkEncoder encoder, String name, boolean append, BufferRecycler bufferRecycler) throws FileNotFoundException
- Throws:
FileNotFoundException
-
-
Method Detail
-
setFinishBlockOnFlush
public LZFFileOutputStream setFinishBlockOnFlush(boolean b)
Method for defining whether call toflush()will also complete current block (similar to callingfinishBlock()) or not.
-
close
public void close() throws IOException- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceChannel- Specified by:
closein interfaceCloseable- Overrides:
closein classFileOutputStream- Throws:
IOException
-
flush
public void flush() throws IOException- Specified by:
flushin interfaceFlushable- Overrides:
flushin classOutputStream- Throws:
IOException
-
write
public void write(byte[] b) throws IOException- Overrides:
writein classFileOutputStream- Throws:
IOException
-
write
public void write(byte[] buffer, int offset, int length) throws IOException- Overrides:
writein classFileOutputStream- Throws:
IOException
-
write
public void write(int b) throws IOException- Overrides:
writein classFileOutputStream- Throws:
IOException
-
write
public void write(InputStream in) throws IOException
- Throws:
IOException
-
write
public int write(ByteBuffer src) throws IOException
- Specified by:
writein interfaceWritableByteChannel- Throws:
IOException
-
write
public void write(FileChannel in) throws IOException
- Throws:
IOException
-
getFinishBlockOnFlush
public boolean getFinishBlockOnFlush()
Accessor for checking whether call to "flush()" will first finish the current block or not
-
finishBlock
public LZFFileOutputStream 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
-
rawWrite
protected void rawWrite(byte[] buffer, int offset, int length) throws IOException- Throws:
IOException
-
checkNotClosed
protected void checkNotClosed() throws IOException- Throws:
IOException
-
-