tribble.io
Class InflaterOutputStream

java.lang.Object
  extended by java.io.OutputStream
      extended by java.io.FilterOutputStream
          extended by tribble.io.InflaterOutputStream
All Implemented Interfaces:
java.io.Closeable, java.io.Flushable

public class InflaterOutputStream
extends java.io.FilterOutputStream

Implements an output stream filter for uncompressing data stored 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 decompresses ("inflates") data like the former class, but writes the decompressed data to an output stream like the latter class.

Since:
2005-05-29
Version:
$Revision: 1.6 $ $Date: 2006/02/14 00:05:53 $
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:
DeflaterInputStream, DeflaterOutputStream, InflaterInputStream, java.util.zip.InflaterOutputStream

Field Summary
protected  byte[] m_buf
          Output buffer for writing compressed data.
protected  long m_inBytes
          Total bytes written to this output stream.
protected  java.util.zip.Inflater m_infl
          Decompressor for this stream.
protected  long m_outBytes
          Total bytes written to the underlying output stream.
(package private) static java.lang.String REV
          Revision information.
 
Fields inherited from class java.io.FilterOutputStream
out
 
Constructor Summary
InflaterOutputStream(java.io.OutputStream out)
          Construct a new output stream with a default decompressor and buffer size.
InflaterOutputStream(java.io.OutputStream out, java.util.zip.Inflater infl)
          Construct a new output stream with the specified decompressor and a default buffer size.
InflaterOutputStream(java.io.OutputStream out, java.util.zip.Inflater infl, int bufLen)
          Construct a new output stream with the specified decompressor and buffer size.
 
Method Summary
 void close()
          Write any remaining uncompressed data to this output stream and close the underlying output stream.
protected  void finalize()
          Finalization.
 void finish()
          Finish writing uncompressed data to this output stream.
 void flush()
          Flush this output stream, forcing any buffered output bytes to be written to the stream.
 long getTotalIn()
          Determine the total number of bytes written to this decompressed output stream.
 long getTotalOut()
          Determine the total number of bytes written to the underlying output stream.
static void main(java.lang.String[] args)
          Uncompress a file containing data stored in the "deflate" compression format.
 void write(byte[] buf)
          Write data to this uncompressed output stream.
 void write(byte[] buf, int off, int len)
          Write data to this uncompressed output stream.
 void write(int b)
          Write data to this uncompressed output 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_infl

protected java.util.zip.Inflater m_infl
Decompressor for this stream.


m_buf

protected byte[] m_buf
Output buffer for writing compressed data.


m_inBytes

protected long m_inBytes
Total bytes written to this output stream.


m_outBytes

protected long m_outBytes
Total bytes written to the underlying output stream.

Constructor Detail

InflaterOutputStream

public InflaterOutputStream(java.io.OutputStream out)
Construct a new output stream with a default decompressor and buffer size.

Parameters:
out - Output stream to write the uncompressed data to.
Since:
1.1, 2005-06-29

InflaterOutputStream

public InflaterOutputStream(java.io.OutputStream out,
                            java.util.zip.Inflater infl)
Construct a new output stream with the specified decompressor and a default buffer size.

Parameters:
out - Output stream to write the uncompressed data to.
infl - Decompressor ("inflater") for this stream.
Since:
1.1, 2005-06-29

InflaterOutputStream

public InflaterOutputStream(java.io.OutputStream out,
                            java.util.zip.Inflater infl,
                            int bufLen)
Construct a new output stream with the specified decompressor and buffer size.

Parameters:
out - Output stream to write the uncompressed data to.
infl - Decompressor ("inflater") for this stream.
bufLen - Decompression buffer size.
Throws:
java.lang.NullPointerException - (unchecked) Thrown if out or infl 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 DeflaterInputStream class.

Usage

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

Options

-j
Use the java.util.zip.InflaterInputStream 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:
DeflaterInputStream.main()

close

public void close()
           throws java.io.IOException
Write any remaining uncompressed data to this output stream and close the underlying output stream.

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.FilterOutputStream
Throws:
java.io.IOException - Thrown if an I/O error occurs.
Since:
1.1, 2005-06-30

flush

public void flush()
           throws java.io.IOException
Flush this output stream, forcing any buffered output bytes to be written to the stream.

Specified by:
flush in interface java.io.Flushable
Overrides:
flush in class java.io.FilterOutputStream
Throws:
java.io.IOException - Thrown if an I/O error occurs.
java.lang.NullPointerException - (unchecked) Thrown if the output stream is closed.
Since:
1.2, 2005-07-02

finish

public void finish()
            throws java.io.IOException
Finish writing uncompressed data to this output stream. Does not close the underlying stream. This is useful when applying multiple filters in succession to the same output stream.

Throws:
java.io.IOException - Thrown if an I/O error occurs.
java.lang.NullPointerException - (unchecked) Thrown if the output stream is closed.
Since:
1.5, 2005-07-25
See Also:
flush(), close()

write

public void write(int b)
           throws java.io.IOException
Write data to this uncompressed output stream.

Overrides:
write in class java.io.FilterOutputStream
Parameters:
b - A single byte of compresses data to decompress and write to the output stream.
Throws:
java.util.zip.ZipException - Thrown if a compression (ZIP) format error occurs.
java.io.IOException - Thrown if an I/O error occurs.
java.lang.NullPointerException - (unchecked) Thrown if the output stream is closed.
Since:
1.1, 2005-06-30

write

public void write(byte[] buf)
           throws java.io.IOException
Write data to this uncompressed output stream.

Overrides:
write in class java.io.FilterOutputStream
Parameters:
buf - Buffer containing compressed data to decompress and write to the output stream.
Throws:
java.util.zip.ZipException - Thrown if a compression (ZIP) format error occurs.
java.io.IOException - Thrown if an I/O error occurs.
java.lang.NullPointerException - (unchecked) Thrown if the output stream is closed.
Since:
1.1, 2005-06-30

write

public void write(byte[] buf,
                  int off,
                  int len)
           throws java.io.IOException
Write data to this uncompressed output stream.

Overrides:
write in class java.io.FilterOutputStream
Parameters:
buf - Buffer containing compressed data to decompress and write to the output stream.
off - Starting offset of the compressed data within buf.
len - Number of bytes to decompress from buf.
Throws:
java.util.zip.ZipException - Thrown if a compression (ZIP) format error occurs.
java.io.IOException - Thrown if an I/O error occurs.
java.lang.NullPointerException - (unchecked) Thrown if the output stream is closed.
Since:
1.1, 2005-06-29

getTotalIn

public long getTotalIn()
Determine the total number of bytes written to this decompressed output stream.

Returns:
The actual number of bytes written to this output stream prior to being decompressed.
Since:
1.2, 2005-06-30

getTotalOut

public long getTotalOut()
Determine the total number of bytes written to the underlying output stream.

Returns:
The number of bytes written to the underlying output stream after being decompressed.
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