com.ning.compress.lzf.util
Class LZFFileInputStream

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

public class LZFFileInputStream
extends FileInputStream

Helper class that allows use of LZF compression even if a library requires use of FileInputStream.

Note that use of this class is not recommended unless you absolutely must use a FileInputStream instance; otherwise basic LZFInputStream (which uses aggregation for underlying streams) is more appropriate

Implementation note: much of the code is just copied from LZFInputStream, so care must be taken to keep implementations in sync if there are fixes.

Since:
0.8

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  boolean inputStreamClosed
          Flag that indicates if we have already called 'inputStream.close()' (to avoid calling it multiple times)
 
Constructor Summary
LZFFileInputStream(File file)
           
LZFFileInputStream(FileDescriptor fdObj)
           
LZFFileInputStream(String name)
           
 
Method Summary
 int available()
           
 void close()
           
 int read()
           
 int read(byte[] b)
           
 int read(byte[] buffer, int offset, int length)
           
protected  int readRaw(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.FileInputStream
finalize, getChannel, getFD
 
Methods inherited from class java.io.InputStream
mark, markSupported, reset
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

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

LZFFileInputStream

public LZFFileInputStream(File file)
                   throws FileNotFoundException
Throws:
FileNotFoundException

LZFFileInputStream

public LZFFileInputStream(FileDescriptor fdObj)

LZFFileInputStream

public LZFFileInputStream(String name)
                   throws FileNotFoundException
Throws:
FileNotFoundException
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()
Overrides:
available in class FileInputStream

close

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

read

public int read()
         throws IOException
Overrides:
read in class FileInputStream
Throws:
IOException

read

public int read(byte[] b)
         throws IOException
Overrides:
read in class FileInputStream
Throws:
IOException

read

public int read(byte[] buffer,
                int offset,
                int length)
         throws IOException
Overrides:
read in class FileInputStream
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 FileInputStream
Throws:
IOException

readyBuffer

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

Throws:
IOException

readRaw

protected final int readRaw(byte[] buffer,
                            int offset,
                            int length)
                     throws IOException
Throws:
IOException


Copyright © 2011. All Rights Reserved.