Class UncompressInputStream

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable

    public class UncompressInputStream
    extends java.io.FilterInputStream
    This class decompresses an input stream containing data compressed with the unix "compress" utility (LZC, a LZW variant). This code is based heavily on the unlzw.c code in gzip-1.2.4 (written by Peter Jannesen) and the original compress code. This version has been modified from the original 0.3-3 version by the Unidata Program Center (support@xxxxxxxxxxxxxxxx) to make the constructor public and to fix a couple of bugs. Also: - markSupported() returns false - add uncompress() static method
    Version:
    0.3-3 06/05/2001, 0.3-5 2008/01/19, 1.0 2018/01/08
    Author:
    Ronald Tschalar, Unidata Program Center, Richard Holland - making LZW_MAGIC package-visible., Fred Hansen (zweibieren@yahoo.com) Fixed available() and the EOF condition for mainloop. Also added some comments., Fred Hansen (zweibieren@yahoo.com) added uncompress(InputStream,OutputStream) and called it from main(String[]) and uncompress(String, FileOutputStream) normalize indentation rewrite skip method amend logging code in uncompress(String, FileOutputStream)
    • Field Summary

      • Fields inherited from class java.io.FilterInputStream

        in
    • Constructor Summary

      Constructors 
      Constructor Description
      UncompressInputStream​(java.io.InputStream is)  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int available()  
      static void main​(java.lang.String[] args)
      Reads a file, uncompresses it, and sends the result to stdout.
      boolean markSupported()
      This stream does not support mark/reset on the stream.
      int read()  
      int read​(byte[] buf, int off, int len)  
      long skip​(long num)  
      static long uncompress​(java.io.InputStream in, java.io.OutputStream out)
      Read an input stream and uncompress it to an output stream.
      static long uncompress​(java.lang.String fileInName, java.io.FileOutputStream out)
      Read a named file and uncompress it.
      • Methods inherited from class java.io.FilterInputStream

        close, mark, read, reset
      • Methods inherited from class java.io.InputStream

        nullInputStream, readAllBytes, readNBytes, readNBytes, transferTo
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • UncompressInputStream

        public UncompressInputStream​(java.io.InputStream is)
                              throws java.io.IOException
        Parameters:
        is - the input stream to decompress
        Throws:
        java.io.IOException - if the header is malformed
    • Method Detail

      • read

        public int read()
                 throws java.io.IOException
        Overrides:
        read in class java.io.FilterInputStream
        Throws:
        java.io.IOException
      • read

        public int read​(byte[] buf,
                        int off,
                        int len)
                 throws java.io.IOException
        Overrides:
        read in class java.io.FilterInputStream
        Throws:
        java.io.IOException
      • skip

        public long skip​(long num)
                  throws java.io.IOException
        Overrides:
        skip in class java.io.FilterInputStream
        Throws:
        java.io.IOException
      • available

        public int available()
                      throws java.io.IOException
        Overrides:
        available in class java.io.FilterInputStream
        Throws:
        java.io.IOException
      • markSupported

        public boolean markSupported()
        This stream does not support mark/reset on the stream.
        Overrides:
        markSupported in class java.io.FilterInputStream
        Returns:
        false
      • uncompress

        public static long uncompress​(java.lang.String fileInName,
                                      java.io.FileOutputStream out)
                               throws java.io.IOException
        Read a named file and uncompress it.
        Parameters:
        fileInName - Name of compressed file.
        out - A destination for the result. It is closed after data is sent.
        Returns:
        number of bytes sent to the output stream,
        Throws:
        java.io.IOException - for any error
      • uncompress

        public static long uncompress​(java.io.InputStream in,
                                      java.io.OutputStream out)
                               throws java.io.IOException
        Read an input stream and uncompress it to an output stream.
        Parameters:
        in - the incoming InputStream. It is NOT closed.
        out - the destination OutputStream. It is NOT closed.
        Returns:
        number of bytes sent to the output stream
        Throws:
        java.io.IOException - for any error
      • main

        public static void main​(java.lang.String[] args)
                         throws java.lang.Exception
        Reads a file, uncompresses it, and sends the result to stdout. Also writes trivial statistics to stderr.
        Parameters:
        args - An array with one String element, the name of the file to read.
        Throws:
        java.io.IOException - for any failure
        java.lang.Exception