Class FileNameUtil

java.lang.Object
org.apache.commons.compress.compressors.FileNameUtil

public class FileNameUtil extends Object
File name mapping code for the compression formats.
Since:
1.4
This class is thread-safe
  • Constructor Details

    • FileNameUtil

      public FileNameUtil(Map<String,String> uncompressSuffix, String defaultExtension)
      sets up the utility with a map of known compressed to uncompressed suffix mappings and the default extension of the format.
      Parameters:
      uncompressSuffix - Map from common file name suffixes of compressed files to the corresponding suffixes of uncompressed files. For example: from ".tgz" to ".tar". This map also contains format-specific suffixes like ".gz" and "-z". These suffixes are mapped to the empty string, as they should simply be removed from the file name when the file is uncompressed.
      defaultExtension - the format's default extension like ".gz"
  • Method Details

    • getCompressedFilename

      Maps the given file name to the name that the file should have after compression. 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 file name.
      Parameters:
      fileName - name of a file
      Returns:
      name of the corresponding compressed file
    • getCompressedFileName

      public String getCompressedFileName(String fileName)
      Maps the given file name to the name that the file should have after compression. 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 file name.
      Parameters:
      fileName - name of a file
      Returns:
      name of the corresponding compressed file
      Since:
      1.25.0
    • getUncompressedFilename

      Maps the given name of a 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 file names with the generic ".gz" suffix (or any other generic gzip suffix) is mapped to a name without that suffix. If no format suffix is detected, then the file name is returned unmapped.
      Parameters:
      fileName - name of a file
      Returns:
      name of the corresponding uncompressed file
    • getUncompressedFileName

      Maps the given name of a 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 file names with the generic ".gz" suffix (or any other generic gzip suffix) is mapped to a name without that suffix. If no format suffix is detected, then the file name is returned unmapped.
      Parameters:
      fileName - name of a file
      Returns:
      name of the corresponding uncompressed file
      Since:
      1.25.0
    • isCompressedFilename

      @Deprecated public boolean isCompressedFilename(String fileName)
      Detects common format suffixes in the given file name.
      Parameters:
      fileName - name of a file
      Returns:
      true if the file name has a common format suffix, false otherwise
    • isCompressedFileName

      public boolean isCompressedFileName(String fileName)
      Detects common format suffixes in the given file name.
      Parameters:
      fileName - name of a file
      Returns:
      true if the file name has a common format suffix, false otherwise
      Since:
      1.25.0