Enum Compression

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Comparable<Compression>

    public enum Compression
    extends java.lang.Enum<Compression>
    An enum representing the compression type of a resource.
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
      BZIP2
      bzip2 compression
      GZIP
      gzip compression
      NONE
      no compression
      XZ
      xz compression
      ZIP
      zip compression
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private Compression()  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static Compression byExtension​(java.lang.String name)
      Determines the compression type depending on the suffix of name.
      static Compression forContentType​(java.lang.String contentType)
      Determines the compression type based on the content type (MIME type).
      static org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream getBZip2InputStream​(java.io.InputStream in)
      Returns a Bzip2 input stream wrapping given input stream.
      static java.io.OutputStream getCompressedFileOutputStream​(java.io.File file)
      Returns a compressing OutputStream for the File file.
      static java.io.OutputStream getCompressedFileOutputStream​(java.nio.file.Path path)
      Returns a compressing OutputStream for the Path path.
      java.io.OutputStream getCompressedOutputStream​(java.io.OutputStream out)
      Returns a compressing OutputStream for out.
      static java.util.zip.GZIPInputStream getGZipInputStream​(java.io.InputStream in)
      Returns a Gzip input stream wrapping given input stream.
      static java.io.InputStream getUncompressedFileInputStream​(java.io.File file)
      Returns an un-compressing InputStream for the File file.
      static java.io.InputStream getUncompressedFileInputStream​(java.nio.file.Path path)
      Returns an un-compressing InputStream for the Path path.
      java.io.InputStream getUncompressedInputStream​(java.io.InputStream in)
      Returns an un-compressing InputStream for in.
      static org.apache.commons.compress.compressors.xz.XZCompressorInputStream getXZInputStream​(java.io.InputStream in)
      Returns a XZ input stream wrapping given input stream.
      static java.util.zip.ZipInputStream getZipInputStream​(java.io.InputStream in)
      Returns a Zip input stream wrapping given input stream.
      static Compression valueOf​(java.lang.String name)
      Returns the enum constant of this type with the specified name.
      static Compression[] values()
      Returns an array containing the constants of this enum type, in the order they are declared.
      • Methods inherited from class java.lang.Enum

        clone, compareTo, equals, finalize, getDeclaringClass, hashCode, name, ordinal, toString, valueOf
      • Methods inherited from class java.lang.Object

        getClass, notify, notifyAll, wait, wait, wait
    • Method Detail

      • values

        public static Compression[] values()
        Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:
        for (Compression c : Compression.values())
            System.out.println(c);
        
        Returns:
        an array containing the constants of this enum type, in the order they are declared
      • valueOf

        public static Compression valueOf​(java.lang.String name)
        Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)
        Parameters:
        name - the name of the enum constant to be returned.
        Returns:
        the enum constant with the specified name
        Throws:
        java.lang.IllegalArgumentException - if this enum type has no constant with the specified name
        java.lang.NullPointerException - if the argument is null
      • byExtension

        public static Compression byExtension​(java.lang.String name)
        Determines the compression type depending on the suffix of name.
        Parameters:
        name - File name including extension
        Returns:
        the compression type
      • forContentType

        public static Compression forContentType​(java.lang.String contentType)
        Determines the compression type based on the content type (MIME type).
        Parameters:
        contentType - the content type
        Returns:
        the compression type
      • getUncompressedInputStream

        public java.io.InputStream getUncompressedInputStream​(java.io.InputStream in)
                                                       throws java.io.IOException
        Returns an un-compressing InputStream for in.
        Parameters:
        in - raw input stream
        Returns:
        un-compressing input stream
        Throws:
        java.io.IOException - if any I/O error occurs
      • getXZInputStream

        public static org.apache.commons.compress.compressors.xz.XZCompressorInputStream getXZInputStream​(java.io.InputStream in)
                                                                                                   throws java.io.IOException
        Returns a XZ input stream wrapping given input stream.
        Parameters:
        in - The raw input stream
        Returns:
        a XZ input stream wrapping given input stream, or null if in is null
        Throws:
        java.io.IOException - if the given input stream does not contain valid BZ2 header
        Since:
        13350
      • getBZip2InputStream

        public static org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream getBZip2InputStream​(java.io.InputStream in)
                                                                                                            throws java.io.IOException
        Returns a Bzip2 input stream wrapping given input stream.
        Parameters:
        in - The raw input stream
        Returns:
        a Bzip2 input stream wrapping given input stream, or null if in is null
        Throws:
        java.io.IOException - if the given input stream does not contain valid BZ2 header
        Since:
        12772 (moved from Utils, there since 7867)
      • getGZipInputStream

        public static java.util.zip.GZIPInputStream getGZipInputStream​(java.io.InputStream in)
                                                                throws java.io.IOException
        Returns a Gzip input stream wrapping given input stream.
        Parameters:
        in - The raw input stream
        Returns:
        a Gzip input stream wrapping given input stream, or null if in is null
        Throws:
        java.io.IOException - if an I/O error has occurred
        Since:
        12772 (moved from Utils, there since 7119)
      • getZipInputStream

        public static java.util.zip.ZipInputStream getZipInputStream​(java.io.InputStream in)
                                                              throws java.io.IOException
        Returns a Zip input stream wrapping given input stream.
        Parameters:
        in - The raw input stream
        Returns:
        a Zip input stream wrapping given input stream, or null if in is null
        Throws:
        java.io.IOException - if an I/O error has occurred
        Since:
        12772 (moved from Utils, there since 7119)
      • getUncompressedFileInputStream

        public static java.io.InputStream getUncompressedFileInputStream​(java.io.File file)
                                                                  throws java.io.IOException
        Returns an un-compressing InputStream for the File file.
        Parameters:
        file - file
        Returns:
        un-compressing input stream
        Throws:
        java.io.IOException - if any I/O error occurs
      • getUncompressedFileInputStream

        public static java.io.InputStream getUncompressedFileInputStream​(java.nio.file.Path path)
                                                                  throws java.io.IOException
        Returns an un-compressing InputStream for the Path path.
        Parameters:
        path - path
        Returns:
        un-compressing input stream
        Throws:
        java.io.IOException - if any I/O error occurs
        Since:
        16816
      • getCompressedOutputStream

        public java.io.OutputStream getCompressedOutputStream​(java.io.OutputStream out)
                                                       throws java.io.IOException
        Returns a compressing OutputStream for out.
        Parameters:
        out - raw output stream
        Returns:
        compressing output stream
        Throws:
        java.io.IOException - if any I/O error occurs
      • getCompressedFileOutputStream

        public static java.io.OutputStream getCompressedFileOutputStream​(java.io.File file)
                                                                  throws java.io.IOException
        Returns a compressing OutputStream for the File file.
        Parameters:
        file - file
        Returns:
        compressing output stream
        Throws:
        java.io.IOException - if any I/O error occurs
        java.nio.file.InvalidPathException - if a Path object cannot be constructed from the abstract path
      • getCompressedFileOutputStream

        public static java.io.OutputStream getCompressedFileOutputStream​(java.nio.file.Path path)
                                                                  throws java.io.IOException
        Returns a compressing OutputStream for the Path path.
        Parameters:
        path - path
        Returns:
        compressing output stream
        Throws:
        java.io.IOException - if any I/O error occurs
        java.nio.file.InvalidPathException - if a Path object cannot be constructed from the abstract path
        Since:
        16816