com.ning.compress.lzf.util
Class LZFFileOutputStream

java.lang.Object
  extended by java.io.OutputStream
      extended by java.io.FileOutputStream
          extended by com.ning.compress.lzf.util.LZFFileOutputStream
All Implemented Interfaces:
Closeable, Flushable

public class LZFFileOutputStream
extends FileOutputStream

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.

Since:
0.8

Field Summary
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
LZFFileOutputStream(File file)
           
LZFFileOutputStream(File file, boolean append)
           
LZFFileOutputStream(FileDescriptor fdObj)
           
LZFFileOutputStream(String name)
           
LZFFileOutputStream(String name, boolean append)
           
 
Method Summary
 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 not
protected  void rawWrite(byte[] buffer, int offset, int length)
           
 LZFFileOutputStream setFinishBlockOnFlush(boolean b)
          Method for defining whether call to flush() will also complete current block (similar to calling finishBlock()) or not.
 void write(byte[] b)
           
 void write(byte[] buffer, int offset, int length)
           
 void write(int b)
           
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.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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'

Since:
0.8

_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
Method Detail

setFinishBlockOnFlush

public LZFFileOutputStream setFinishBlockOnFlush(boolean b)
Method for defining whether call to flush() will also complete current block (similar to calling finishBlock()) or not.


close

public void close()
           throws IOException
Specified by:
close in interface Closeable
Overrides:
close in class FileOutputStream
Throws:
IOException

flush

public void flush()
           throws IOException
Specified by:
flush in interface Flushable
Overrides:
flush in class OutputStream
Throws:
IOException

write

public void write(byte[] b)
           throws IOException
Overrides:
write in class FileOutputStream
Throws:
IOException

write

public void write(byte[] buffer,
                  int offset,
                  int length)
           throws IOException
Overrides:
write in class FileOutputStream
Throws:
IOException

write

public void write(int b)
           throws IOException
Overrides:
write in class FileOutputStream
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


Copyright © 2011. All Rights Reserved.