tribble.io
Class DeflaterInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by java.io.FilterInputStream
          extended by tribble.io.DeflaterInputStream
All Implemented Interfaces:
java.io.Closeable

public class DeflaterInputStream
extends java.io.FilterInputStream

Implements an input stream filter for compressing data in the "deflate" compression format.

This class serves as a complement to the standard java.util.zip.InflaterInputStream and java.util.zip.DeflaterOutputStream classes. It compresses ("deflates") data like the latter class, but reads the compressed data from an input stream like the former class.

Since:
2005-05-29
Version:
$Revision: 1.6 $ $Date: 2006/02/13 23:58:17 $
Author:
David R. Tribble (david@tribble.com).

Copyright ©2005 by David R. Tribble, all rights reserved.
Permission is granted to freely use and distribute this source code provided that the original copyright and authorship notices remain intact.

See Also:
InflaterOutputStream, DeflaterOutputStream, InflaterInputStream, java.util.zip.DeflaterInputStream

Field Summary
protected  byte[] m_buf
          Input buffer for reading compressed data.
protected  java.util.zip.Deflater m_defl
          Compressor for this stream.
protected  long m_inBytes
          Total bytes read from the underlying input stream.
protected  long m_outBytes
          Total bytes returned from this input stream.
(package private) static java.lang.String REV
          Revision information.
 
Fields inherited from class java.io.FilterInputStream
in
 
Constructor Summary
DeflaterInputStream(java.io.InputStream in)
          Construct a new input stream with a default compressor and buffer size.
DeflaterInputStream(java.io.InputStream in, java.util.zip.Deflater defl)
          Construct a new input stream with the specified compressor and a default buffer size.
DeflaterInputStream(java.io.InputStream in, java.util.zip.Deflater defl, int bufLen)
          Construct a new input stream with the specified compressor and buffer size.
 
Method Summary
 int available()
          Determine the number of bytes that can be read from this input stream without blocking.
 void close()
          Close this input stream and its underlying input stream, discarding any pending uncompressed data.
protected  void finalize()
          Finalization.
 long getTotalIn()
          Determine the total number of bytes read from the underlying input stream.
 long getTotalOut()
          Determine the total number of bytes read from this compressed input stream.
static void main(java.lang.String[] args)
          Uncompress a file containing data stored in the "deflate" compression format.
 void mark(int limit)
          This operation is not supported.
 boolean markSupported()
          Test if this input stream supports the mark() and reset() methods.
 int read()
          Read compressed data from the input stream.
 int read(byte[] buf)
          Read compressed data from the input stream.
 int read(byte[] buf, int off, int len)
          Read compressed data from the input stream.
 void reset()
          This operation is not supported.
 long skip(long n)
          Skip over and discard data from the input stream.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

REV

static final java.lang.String REV
Revision information.

See Also:
Constant Field Values

m_defl

protected java.util.zip.Deflater m_defl
Compressor for this stream.


m_buf

protected byte[] m_buf
Input buffer for reading compressed data.


m_inBytes

protected long m_inBytes
Total bytes read from the underlying input stream.


m_outBytes

protected long m_outBytes
Total bytes returned from this input stream.

Constructor Detail

DeflaterInputStream

public DeflaterInputStream(java.io.InputStream in)
Construct a new input stream with a default compressor and buffer size.

Parameters:
in - Input stream to read the uncompressed data to.
Since:
1.1, 2005-06-29

DeflaterInputStream

public DeflaterInputStream(java.io.InputStream in,
                           java.util.zip.Deflater defl)
Construct a new input stream with the specified compressor and a default buffer size.

Parameters:
in - Input stream to read the uncompressed data to.
defl - Compressor ("deflater") for this stream.
Since:
1.1, 2005-06-29

DeflaterInputStream

public DeflaterInputStream(java.io.InputStream in,
                           java.util.zip.Deflater defl,
                           int bufLen)
Construct a new input stream with the specified compressor and buffer size.

Parameters:
in - Input stream to read the uncompressed data to.
defl - Compressor ("deflater") for this stream.
bufLen - Compression buffer size.
Throws:
java.lang.NullPointerException - (unchecked) Thrown if in or defl is null.
java.lang.IllegalArgumentException - (unchecked) Thrown if bufLen is less than 1.
Since:
1.1, 2005-06-29
Method Detail

main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception
Uncompress a file containing data stored in the "deflate" compression format.

The file to be uncompressed should contain compressed data stored in the "deflate" compression format, such as the output from the InflaterOutputStream class.

Usage

java tribble.io.DeflaterInputStream [-option...] file

Options

-j
Use the java.util.zip.DeflaterOutputStream class instead of this class.
-o file
Output filename. By default, the output is written to standard output.
file
Input filename. If this is "-", input is read from standard input.

Parameters:
args - Command line arguments.
Throws:
java.lang.Exception
Since:
1.1, 2005-06-29
See Also:
InflaterOutputStream.main()

close

public void close()
           throws java.io.IOException
Close this input stream and its underlying input stream, discarding any pending uncompressed data.

Note that this method can be called multiple times with no ill effects.

Specified by:
close in interface java.io.Closeable
Overrides:
close in class java.io.FilterInputStream
Throws:
java.io.IOException - Thrown if an I/O error occurs.
Since:
1.1, 2005-06-29

read

public int read()
         throws java.io.IOException
Read compressed data from the input stream. This will block until some input can be read and compressed.

Overrides:
read in class java.io.FilterInputStream
Returns:
A single byte of compressed data (in the range [0x00,0xFF]), or -1 if the end of the uncompressed input stream is reached.
Throws:
java.io.IOException - Thrown if an I/O (read) error occurs.
java.lang.NullPointerException - (unchecked) Thrown if the underlying input stream is closed.
Since:
1.1, 2005-06-29

read

public int read(byte[] buf)
         throws java.io.IOException
Read compressed data from the input stream. This will block until some input can be read and compressed.

Overrides:
read in class java.io.FilterInputStream
Parameters:
buf - Buffer into which the data is read. An attempt is made to fill the entire array.
Returns:
The actual number of bytes read, or -1 if the end of the uncompressed input stream is reached.
Throws:
java.io.IOException - Thrown if an I/O (read) error occurs.
java.lang.NullPointerException - (unchecked) Thrown if the underlying input stream is closed.
Since:
1.1, 2005-06-29

read

public int read(byte[] buf,
                int off,
                int len)
         throws java.io.IOException
Read compressed data from the input stream. This will block until some input can be read and compressed.

Overrides:
read in class java.io.FilterInputStream
Parameters:
buf - Buffer into which the data is read.
off - Starting offset of the data within buf.
len - Maximum number of compressed bytes to read into buf.
Returns:
The actual number of bytes read, or -1 if the end of the uncompressed input stream is reached.
Throws:
java.io.IOException - Thrown if an I/O (read) error occurs.
java.lang.NullPointerException - (unchecked) Thrown if the underlying input stream is closed.
Since:
1.1, 2005-06-29

skip

public long skip(long n)
          throws java.io.IOException
Skip over and discard data from the input stream. This method may block until the specified number of bytes are read and skipped.

Overrides:
skip in class java.io.FilterInputStream
Parameters:
n - Number of bytes to be skipped.
Returns:
The actual number of bytes skipped.
Throws:
java.io.IOException - Thrown if an I/O (read) error occurs.
java.lang.NullPointerException - (unchecked) Thrown if the underlying input stream is closed.
Since:
1.1, 2005-06-29

available

public int available()
              throws java.io.IOException
Determine the number of bytes that can be read from this input stream without blocking.

Programs should not count on this method to return the actual number of bytes that could be read without blocking.

Overrides:
available in class java.io.FilterInputStream
Returns:
Zero after the end of the underlying input stream has been reached, otherwise always returns 1.
Throws:
java.io.IOException - Thrown if an I/O (read) error occurs.
Since:
1.1, 2005-06-29

markSupported

public boolean markSupported()
Test if this input stream supports the mark() and reset() methods. These operations are not supported.

Overrides:
markSupported in class java.io.FilterInputStream
Returns:
False, always.
Since:
1.1, 2005-06-29

mark

public void mark(int limit)
This operation is not supported.

Overrides:
mark in class java.io.FilterInputStream
Parameters:
limit - Maximum bytes that can be read before invalidating the position marker.
Since:
1.1, 2005-06-29

reset

public void reset()
           throws java.io.IOException
This operation is not supported.

Overrides:
reset in class java.io.FilterInputStream
Throws:
java.io.IOException - Always thrown.
Since:
1.1, 2005-06-29

getTotalIn

public long getTotalIn()
Determine the total number of bytes read from the underlying input stream.

Returns:
The actual number of bytes read from the underlying input stream prior to being compressed.
Since:
1.2, 2005-06-30

getTotalOut

public long getTotalOut()
Determine the total number of bytes read from this compressed input stream.

Returns:
The number of bytes read from this input stream after being compressed.
Since:
1.2, 2005-06-30

finalize

protected void finalize()
                 throws java.lang.Throwable
Finalization.

Overrides:
finalize in class java.lang.Object
Throws:
java.lang.Throwable
Since:
1.6, 2006-02-13