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
FileOutputStream
instance; 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
_cfgFinishBlockOnFlush
Configuration setting that governs whether basic 'flush()' should first complete a block or not.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
-
Constructor Summary
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
checkNotClosed()
void
close()
LZFFileOutputStream
finishBlock()
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.void
flush()
boolean
getFinishBlockOnFlush()
Accessor for checking whether call to "flush()" will first finish the current block or notboolean
isOpen()
protected void
rawWrite(byte[] buffer, int offset, int length)
LZFFileOutputStream
setFinishBlockOnFlush(boolean b)
Method for defining whether call toflush()
will also complete current block (similar to callingfinishBlock()
) or not.void
write(byte[] b)
void
write(byte[] buffer, int offset, int length)
void
write(int b)
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.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:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceChannel
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classFileOutputStream
- Throws:
IOException
-
flush
public void flush() throws IOException
- Specified by:
flush
in interfaceFlushable
- Overrides:
flush
in classOutputStream
- Throws:
IOException
-
write
public void write(byte[] b) throws IOException
- Overrides:
write
in classFileOutputStream
- Throws:
IOException
-
write
public void write(byte[] buffer, int offset, int length) throws IOException
- Overrides:
write
in classFileOutputStream
- Throws:
IOException
-
write
public void write(int b) throws IOException
- Overrides:
write
in classFileOutputStream
- Throws:
IOException
-
write
public void write(InputStream in) throws IOException
- Throws:
IOException
-
write
public int write(ByteBuffer src) throws IOException
- Specified by:
write
in 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 IOException
Compress 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
-
-