com.ning.compress.lzf
Class LZFOutputStream

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

public class LZFOutputStream
extends OutputStream

Decorator OutputStream implementation that will compress output using LZF compression algorithm.

Author:
jon hartlaub, tatu

Field Summary
protected  boolean _cfgFinishBlockOnFlush
          Configuration setting that governs whether basic 'flush()' should first complete a block or not.
protected  byte[] _outputBuffer
           
protected  OutputStream _outputStream
           
protected  boolean _outputStreamClosed
          Flag that indicates if we have already called '_outputStream.close()' (to avoid calling it multiple times)
protected  int _position
           
 
Constructor Summary
LZFOutputStream(OutputStream outputStream)
           
 
Method Summary
 void close()
           
 LZFOutputStream 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
 OutputStream getUnderlyingOutputStream()
          Method that can be used to find underlying OutputStream that we write encoded LZF encoded data into, after compressing it.
 LZFOutputStream setFinishBlockOnFlush(boolean b)
          Method for defining whether call to flush() will also complete current block (similar to calling finishBlock()) or not.
 void write(byte[] buffer, int offset, int length)
           
 void write(int singleByte)
           
protected  void writeCompressedBlock()
          Compress and write the current block to the OutputStream
 
Methods inherited from class java.io.OutputStream
write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_outputStream

protected final OutputStream _outputStream

_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

LZFOutputStream

public LZFOutputStream(OutputStream outputStream)
Method Detail

setFinishBlockOnFlush

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

Since:
0.8

write

public void write(int singleByte)
           throws IOException
Specified by:
write in class OutputStream
Throws:
IOException

write

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

flush

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

close

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

getUnderlyingOutputStream

public OutputStream getUnderlyingOutputStream()
Method that can be used to find underlying OutputStream that we write encoded LZF encoded data into, after compressing it. Will never return null; although underlying stream may be closed (if this stream has been closed).

Since:
0.8

getFinishBlockOnFlush

public boolean getFinishBlockOnFlush()
Accessor for checking whether call to "flush()" will first finish the current block or not

Since:
0.8

finishBlock

public LZFOutputStream 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
Since:
0.8

writeCompressedBlock

protected void writeCompressedBlock()
                             throws IOException
Compress and write the current block to the OutputStream

Throws:
IOException


Copyright © 2011. All Rights Reserved.