com.ning.compress.lzf
Class LZFInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by com.ning.compress.lzf.LZFInputStream
All Implemented Interfaces:
Closeable

public class LZFInputStream
extends InputStream


Field Summary
protected  boolean _cfgFullReads
          Flag that indicates whether we force full reads (reading of as many bytes as requested), or 'optimal' reads (up to as many as available, but at least one).
protected  InputStream inputStream
          stream to be decompressed
protected  boolean inputStreamClosed
          Flag that indicates if we have already called 'inputStream.close()' (to avoid calling it multiple times)
 
Constructor Summary
LZFInputStream(InputStream inputStream)
           
LZFInputStream(InputStream in, boolean fullReads)
           
 
Method Summary
 int available()
          Method is overridden to report number of bytes that can now be read from decoded data buffer, without reading bytes from the underlying stream.
 void close()
           
 void discardBuffered()
          Method that can be called to discard any already buffered input, read from input source.
 InputStream getUnderlyingInputStream()
          Method that can be used to find underlying InputStream that we read from to get LZF encoded data to decode.
 int read()
           
 int read(byte[] buffer)
           
 int read(byte[] buffer, int offset, int length)
           
protected  boolean readyBuffer()
          Fill the uncompressed bytes buffer by reading the underlying inputStream.
 void setUseFullReads(boolean b)
          Method that can be used define whether reads should be "full" or "optimal": former means that full compressed blocks are read right away as needed, optimal that only smaller chunks are read at a time, more being read as needed.
 long skip(long n)
          Overridden to just skip at most a single chunk at a time
 
Methods inherited from class java.io.InputStream
mark, markSupported, reset
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

inputStream

protected final InputStream inputStream
stream to be decompressed


inputStreamClosed

protected boolean inputStreamClosed
Flag that indicates if we have already called 'inputStream.close()' (to avoid calling it multiple times)


_cfgFullReads

protected boolean _cfgFullReads
Flag that indicates whether we force full reads (reading of as many bytes as requested), or 'optimal' reads (up to as many as available, but at least one). Default is false, meaning that 'optimal' read is used.

Constructor Detail

LZFInputStream

public LZFInputStream(InputStream inputStream)
               throws IOException
Throws:
IOException

LZFInputStream

public LZFInputStream(InputStream in,
                      boolean fullReads)
               throws IOException
Parameters:
in - Underlying input stream to use
fullReads - Whether read(byte[]) should try to read exactly as many bytes as requested (true); or just however many happen to be available (false)
Throws:
IOException
Method Detail

setUseFullReads

public void setUseFullReads(boolean b)
Method that can be used define whether reads should be "full" or "optimal": former means that full compressed blocks are read right away as needed, optimal that only smaller chunks are read at a time, more being read as needed.


available

public int available()
Method is overridden to report number of bytes that can now be read from decoded data buffer, without reading bytes from the underlying stream. Never throws an exception; returns number of bytes available without further reads from underlying source; -1 if stream has been closed, or 0 if an actual read (and possible blocking) is needed to find out.

Overrides:
available in class InputStream

read

public int read()
         throws IOException
Specified by:
read in class InputStream
Throws:
IOException

read

public int read(byte[] buffer)
         throws IOException
Overrides:
read in class InputStream
Throws:
IOException

read

public int read(byte[] buffer,
                int offset,
                int length)
         throws IOException
Overrides:
read in class InputStream
Throws:
IOException

close

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

skip

public long skip(long n)
          throws IOException
Overridden to just skip at most a single chunk at a time

Overrides:
skip in class InputStream
Throws:
IOException

getUnderlyingInputStream

public InputStream getUnderlyingInputStream()
Method that can be used to find underlying InputStream that we read from to get LZF encoded data to decode. Will never return null; although underlying stream may be closed (if this stream has been closed).

Since:
0.8

discardBuffered

public void discardBuffered()
Method that can be called to discard any already buffered input, read from input source. Specialized method that only makes sense if the underlying InputStream can be repositioned reliably.

Since:
0.9

readyBuffer

protected boolean readyBuffer()
                       throws IOException
Fill the uncompressed bytes buffer by reading the underlying inputStream.

Throws:
IOException


Copyright © 2011. All Rights Reserved.