Interface Compressor

  • All Known Implementing Classes:
    AbstractCompressor, BZip2Compressor, DeflateCompressor, GZIPCompressor, LZMACompressor

    public interface Compressor
    A generic interface for simple compression and decompression of data streams using various compression algorithms. In addition to supporting the filtered stream model used in the Java I/O libraries, Compressors use a pipe-style model in which data is transformed as it copied through from an input stream to an output stream. This style is more convenient in many applications.
    Since:
    3.0
    Author:
    Chris Jennings
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      void compress​(java.io.File in, java.io.File out)
      Compresses a file, writing the result to another file.
      void compress​(java.io.File in, java.io.File out, ProgressListener li)
      Compresses a file, writing the result to another file.
      void compress​(java.io.InputStream in, java.io.OutputStream out)
      Reads the data from the input stream, compresses it, and writes it to the output stream.
      void decompress​(java.io.File in, java.io.File out)
      Decompresses a file, writing the result to another file.
      void decompress​(java.io.File in, java.io.File out, ProgressListener li)
      Decompresses a file, writing the result to another file.
      void decompress​(java.io.InputStream in, java.io.OutputStream out)
      Reads compressed data from the input stream, decompresses it, and writes it to the output stream.
      java.io.InputStream filter​(java.io.InputStream in)
      Returns an input stream that reads decompresses data from a stream of compressed data.
      java.io.OutputStream filter​(java.io.OutputStream out)
      Returns an output stream that compresses data as it writes it to an existing stream.
      int getCompressionLevel()
      Returns the current compression level.
      void setCompressionLevel​(int level)
      Sets the compression level for future compression operations.
    • Method Detail

      • setCompressionLevel

        void setCompressionLevel​(int level)
        Sets the compression level for future compression operations. The compression level is an integer between 0 and 9 inclusive that indicates whether the compressor should favour low resource requirements (such as CPU time and memory) or high compression ratios (9=maximum compression). For some implementations, this value may have no effect.

        Each compressor has its own default compression level chosen to balance the amount of compression against the resources required to compress and/or decompress the data. Setting the compression level higher than its default may result in a sharp increase in resource use, particularly during compression.

        Parameters:
        level - the compression level from 0 to 9, with higher values suggesting that the algorithm should try harder to compress the data
        Throws:
        java.lang.IllegalArgumentException - if the requested level is out of range
      • getCompressionLevel

        int getCompressionLevel()
        Returns the current compression level.
        Returns:
        the current compression level, from 0 to 9 inclusive
      • compress

        void compress​(java.io.InputStream in,
                      java.io.OutputStream out)
               throws java.io.IOException
        Reads the data from the input stream, compresses it, and writes it to the output stream.
        Parameters:
        in - the source for data to compress
        out - the sink for compressed data
        Throws:
        java.io.IOException - if an error occurs during compression
      • decompress

        void decompress​(java.io.InputStream in,
                        java.io.OutputStream out)
                 throws java.io.IOException
        Reads compressed data from the input stream, decompresses it, and writes it to the output stream.
        Parameters:
        in - the source of data to decompress
        out - the sink for decompressed data
        Throws:
        java.io.IOException - if an error occurs during decompression
      • compress

        void compress​(java.io.File in,
                      java.io.File out)
               throws java.io.IOException
        Compresses a file, writing the result to another file.
        Parameters:
        in - the file to compress
        out - the destination
        Throws:
        java.io.IOException - if an error occurs
      • compress

        void compress​(java.io.File in,
                      java.io.File out,
                      ProgressListener li)
               throws java.io.IOException
        Compresses a file, writing the result to another file.
        Parameters:
        in - the file to compress
        out - the destination
        li - a listener that will be updated with compression progress
        Throws:
        java.io.IOException - if an error occurs
      • decompress

        void decompress​(java.io.File in,
                        java.io.File out)
                 throws java.io.IOException
        Decompresses a file, writing the result to another file.
        Parameters:
        in - the file to decompress
        out - the destination
        Throws:
        java.io.IOException - if an error occurs
      • decompress

        void decompress​(java.io.File in,
                        java.io.File out,
                        ProgressListener li)
                 throws java.io.IOException
        Decompresses a file, writing the result to another file.
        Parameters:
        in - the file to decompress
        out - the destination
        li - a listener that will be updated with the decompression progress
        Throws:
        java.io.IOException - if an error occurs
      • filter

        java.io.OutputStream filter​(java.io.OutputStream out)
                             throws java.io.IOException
        Returns an output stream that compresses data as it writes it to an existing stream.
        Parameters:
        out - the stream to write compressed data to
        Returns:
        a filter stream that will compress data and write it to out
        Throws:
        java.io.IOException - if an error occurs while creating the stream
      • filter

        java.io.InputStream filter​(java.io.InputStream in)
                            throws java.io.IOException
        Returns an input stream that reads decompresses data from a stream of compressed data.
        Parameters:
        in - the stream to read compressed data from
        Returns:
        a filter stream that will decompress data from in as it is read from
        Throws:
        java.io.IOException - if an error occurs while creating the stream