uk.ac.starlink.util

## Class Compression

- java.lang.Object
- - uk.ac.starlink.util.Compression

-     public abstract class Compression
      extends java.lang.Object

  Characterises the compression status of a stream, and provides methods for decompressing it.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static Compression` | `BZIP2` A Compression object representing BZip2 compression.
    `static Compression` | `COMPRESS` A Compression object representing Unix compress-type compression.
    `static Compression` | `GZIP` A Compression object representing GZip compression.
    `static int` | `MAGIC_SIZE` Number of bytes needed to determine compression type (magic number).
    `static Compression` | `NONE` A Compression object representing no compression (or perhaps an unknown one).

  - ### Method Summary

    All Methods Static Methods Instance Methods Abstract Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `abstract java.io.InputStream` | `decompress(java.io.InputStream raw)` Returns a stream which is a decompressed version of the input stream, according to this objects compression type.
    `static java.io.InputStream` | `decompressStatic(java.io.InputStream raw)` Returns a decompressed version of the given input stream.
    `static Compression` | `getCompression(byte[] magic)` Returns a Compression object characterising the compression (if any) represented by a given magic number.
    `java.lang.String` | `toString()` Returns the name of this compression type.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Field Detail

    - #### MAGIC_SIZE

          public static final int MAGIC_SIZE

      Number of bytes needed to determine compression type (magic number).
      See Also:
        Constant Field Values

    - #### NONE

          public static final Compression NONE

      A Compression object representing no compression (or perhaps an unknown one). The `decompress` method will return the raw input stream unchanged.

    - #### GZIP

          public static final Compression GZIP

      A Compression object representing GZip compression.

    - #### BZIP2

          public static final Compression BZIP2

      A Compression object representing BZip2 compression.

    - #### COMPRESS

          public static final Compression COMPRESS

      A Compression object representing Unix compress-type compression.

  - ### Method Detail

    - #### decompress

          public abstract java.io.InputStream decompress(java.io.InputStream raw)
                                                  throws java.io.IOException

      Returns a stream which is a decompressed version of the input stream, according to this objects compression type.
      Parameters:
        `raw` - the raw input stream
      Returns:
        a stream giving the decompressed version of `raw`
      Throws:
        `java.io.IOException`

    - #### getCompression

          public static Compression getCompression(byte[] magic)

      Returns a Compression object characterising the compression (if any) represented by a given magic number.
      Parameters:
        `magic` - a buffer containing the first `MAGIC_SIZE` bytes of input of the stream to be characterised
      Returns:
        a `Compression` object of the type represented by `magic`
      Throws:
        `java.lang.IllegalArgumentException` - if `magic.length<MAGIC_SIZE`

    - #### decompressStatic

          public static java.io.InputStream decompressStatic(java.io.InputStream raw)
                                                      throws java.io.IOException

      Returns a decompressed version of the given input stream.
      Parameters:
        `raw` - the raw input stream
      Returns:
        the decompressed version of `raw`
      Throws:
        `java.io.IOException`

    - #### toString

          public java.lang.String toString()

      Returns the name of this compression type.
      Overrides:
        `toString` in class `java.lang.Object`
      Returns:
        string representation