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
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 class
This simple wrapper is needed to re-route read calls so that they will use "raw" writes -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected boolean
Configuration setting that governs whether basic 'flush()' should first complete a block or not.private final ChunkEncoder
protected byte[]
protected boolean
Flag that indicates if we have already called '_outputStream.close()' (to avoid calling it multiple times)protected int
private final BufferRecycler
private final LZFFileOutputStream.Wrapper
Wrapper 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 void
void
close()
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
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) 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
Compress and write the current block to the OutputStreamMethods inherited from class java.io.FileOutputStream
getChannel, getFD
Methods inherited from class java.io.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
public boolean isOpen() -
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceChannel
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classFileOutputStream
- Throws:
IOException
-
flush
- Specified by:
flush
in interfaceFlushable
- Overrides:
flush
in classOutputStream
- Throws:
IOException
-
write
- Overrides:
write
in classFileOutputStream
- Throws:
IOException
-
write
- Overrides:
write
in classFileOutputStream
- Throws:
IOException
-
write
- Overrides:
write
in classFileOutputStream
- Throws:
IOException
-
write
- Throws:
IOException
-
write
- Specified by:
write
in 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
-