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
Helper class that allows use of LZF compression even if a library requires
use of
FileOutputStream.
Note that use of this class is not recommended unless you absolutely must
use a FileOutputStream instance; otherwise basic LZFOutputStream
(which uses aggregation for underlying streams) is more appropriate
Implementation note: much of the code is just copied from LZFOutputStream,
so care must be taken to keep implementations in sync if there are fixes.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate final classThis simple wrapper is needed to re-route read calls so that they will use "raw" writes -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected booleanConfiguration setting that governs whether basic 'flush()' should first complete a block or not.private final ChunkEncoderprotected byte[]protected booleanFlag that indicates if we have already called '_outputStream.close()' (to avoid calling it multiple times)protected intprivate final BufferRecyclerprivate final LZFFileOutputStream.WrapperWrapper object we use to allow decoder to write directly to the stream, without ending in infinite loop...private static final int -
Constructor Summary
ConstructorsConstructorDescriptionLZFFileOutputStream(ChunkEncoder encoder, File file) LZFFileOutputStream(ChunkEncoder encoder, FileDescriptor fdObj) LZFFileOutputStream(ChunkEncoder encoder, FileDescriptor fdObj, BufferRecycler bufferRecycler) LZFFileOutputStream(ChunkEncoder encoder, File file, boolean append) LZFFileOutputStream(ChunkEncoder encoder, File file, boolean append, BufferRecycler bufferRecycler) LZFFileOutputStream(ChunkEncoder encoder, File file, BufferRecycler bufferRecycler) LZFFileOutputStream(ChunkEncoder encoder, String name) LZFFileOutputStream(ChunkEncoder encoder, String name, boolean append) LZFFileOutputStream(ChunkEncoder encoder, String name, boolean append, BufferRecycler bufferRecycler) LZFFileOutputStream(ChunkEncoder encoder, String name, BufferRecycler bufferRecycler) LZFFileOutputStream(File file) LZFFileOutputStream(File file, boolean append) LZFFileOutputStream(String name) LZFFileOutputStream(String name, boolean append) -
Method Summary
Modifier and TypeMethodDescriptionprotected voidvoidclose()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()booleanAccessor for checking whether call to "flush()" will first finish the current block or notbooleanisOpen()protected voidrawWrite(byte[] buffer, int offset, int length) setFinishBlockOnFlush(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 voidCompress and write the current block to the OutputStreamMethods inherited from class FileOutputStream
getChannel, getFDMethods inherited from class OutputStream
nullOutputStream
-
Field Details
-
OUTPUT_BUFFER_SIZE
private static final int OUTPUT_BUFFER_SIZE- See Also:
-
_encoder
-
_recycler
-
_outputBuffer
protected byte[] _outputBuffer -
_position
protected int _position -
_cfgFinishBlockOnFlush
protected boolean _cfgFinishBlockOnFlushConfiguration setting that governs whether basic 'flush()' should first complete a block or not.Default value is 'true'.
-
_outputStreamClosed
protected boolean _outputStreamClosedFlag that indicates if we have already called '_outputStream.close()' (to avoid calling it multiple times) -
_wrapper
Wrapper object we use to allow decoder to write directly to the stream, without ending in infinite loop...
-
-
Constructor Details
-
LZFFileOutputStream
- Throws:
FileNotFoundException
-
LZFFileOutputStream
- Throws:
FileNotFoundException
-
LZFFileOutputStream
-
LZFFileOutputStream
- Throws:
FileNotFoundException
-
LZFFileOutputStream
- Throws:
FileNotFoundException
-
LZFFileOutputStream
- Throws:
FileNotFoundException
-
LZFFileOutputStream
public LZFFileOutputStream(ChunkEncoder encoder, File file, boolean append) throws FileNotFoundException - Throws:
FileNotFoundException
-
LZFFileOutputStream
-
LZFFileOutputStream
- 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 Details
-
setFinishBlockOnFlush
Method for defining whether call toflush()will also complete current block (similar to callingfinishBlock()) or not. -
isOpen
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceChannel- Specified by:
closein interfaceCloseable- Overrides:
closein classFileOutputStream- Throws:
IOException
-
flush
- Specified by:
flushin interfaceFlushable- Overrides:
flushin classOutputStream- Throws:
IOException
-
write
- Overrides:
writein classFileOutputStream- Throws:
IOException
-
write
- Overrides:
writein classFileOutputStream- Throws:
IOException
-
write
- Overrides:
writein classFileOutputStream- Throws:
IOException
-
write
- Throws:
IOException
-
write
- Specified by:
writein interfaceWritableByteChannel- Throws:
IOException
-
write
- Throws:
IOException
-
getFinishBlockOnFlush
public boolean getFinishBlockOnFlush()Accessor for checking whether call to "flush()" will first finish the current block or not -
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. 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
Compress and write the current block to the OutputStream- Throws:
IOException
-
rawWrite
- Throws:
IOException
-
checkNotClosed
- Throws:
IOException
-