org.apache.commons.compress.compressors.gzip
Class GzipUtils

java.lang.Object
  extended by org.apache.commons.compress.compressors.gzip.GzipUtils

public class GzipUtils
extends java.lang.Object

Utility code for the gzip compression format.


Field Summary
private static java.util.Map compressSuffix
          Map from common filename suffixes to the suffixes that identify gzipped versions of those file types.
private static java.util.Map uncompressSuffix
          Map from common filename suffixes of gzipped files to the corresponding suffixes of uncompressed files.
 
Constructor Summary
private GzipUtils()
          Private constructor to prevent instantiation of this utility class.
 
Method Summary
static java.lang.String getCompressedFilename(java.lang.String filename)
          Maps the given filename to the name that the file should have after compression with gzip.
static java.lang.String getUncompressedFilename(java.lang.String filename)
          Maps the given name of a gzip-compressed file to the name that the file should have after uncompression.
static boolean isCompressedFilename(java.lang.String filename)
          Detects common gzip suffixes in the given filename.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

compressSuffix

private static final java.util.Map compressSuffix
Map from common filename suffixes to the suffixes that identify gzipped versions of those file types. For example: from ".tar" to ".tgz".


uncompressSuffix

private static final java.util.Map uncompressSuffix
Map from common filename suffixes of gzipped files to the corresponding suffixes of uncompressed files. For example: from ".tgz" to ".tar".

This map also contains gzip-specific suffixes like ".gz" and "-z". These suffixes are mapped to the empty string, as they should simply be removed from the filename when the file is uncompressed.

Constructor Detail

GzipUtils

private GzipUtils()
Private constructor to prevent instantiation of this utility class.

Method Detail

isCompressedFilename

public static boolean isCompressedFilename(java.lang.String filename)
Detects common gzip suffixes in the given filename.

Parameters:
filename - name of a file
Returns:
true if the filename has a common gzip suffix, false otherwise

getUncompressedFilename

public static java.lang.String getUncompressedFilename(java.lang.String filename)
Maps the given name of a gzip-compressed file to the name that the file should have after uncompression. Commonly used file type specific suffixes like ".tgz" or ".svgz" are automatically detected and correctly mapped. For example the name "package.tgz" is mapped to "package.tar". And any filenames with the generic ".gz" suffix (or any other generic gzip suffix) is mapped to a name without that suffix. If no gzip suffix is detected, then the filename is returned unmapped.

Parameters:
filename - name of a file
Returns:
name of the corresponding uncompressed file

getCompressedFilename

public static java.lang.String getCompressedFilename(java.lang.String filename)
Maps the given filename to the name that the file should have after compression with gzip. Common file types with custom suffixes for compressed versions are automatically detected and correctly mapped. For example the name "package.tar" is mapped to "package.tgz". If no custom mapping is applicable, then the default ".gz" suffix is appended to the filename.

Parameters:
filename - name of a file
Returns:
name of the corresponding compressed file