Class FileNameUtil


  • public class FileNameUtil
    extends java.lang.Object
    File name mapping code for the compression formats.
    Since:
    1.4
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.Map<java.lang.String,​java.lang.String> compressSuffix
      Map from common file name suffixes to the suffixes that identify compressed versions of those file types.
      private java.lang.String defaultExtension
      The format's default extension.
      private int longestCompressedSuffix
      Length of the longest compressed suffix.
      private int longestUncompressedSuffix
      Length of the longest uncompressed suffix.
      private int shortestCompressedSuffix
      Length of the shortest compressed suffix.
      private int shortestUncompressedSuffix
      Length of the shortest uncompressed suffix longer than the empty string.
      private java.util.Map<java.lang.String,​java.lang.String> uncompressSuffix
      Map from common file name suffixes of compressed files to the corresponding suffixes of uncompressed files.
    • Constructor Summary

      Constructors 
      Constructor Description
      FileNameUtil​(java.util.Map<java.lang.String,​java.lang.String> uncompressSuffix, java.lang.String defaultExtension)
      sets up the utility with a map of known compressed to uncompressed suffix mappings and the default extension of the format.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.String getCompressedFilename​(java.lang.String fileName)
      Maps the given file name to the name that the file should have after compression.
      java.lang.String getUncompressedFilename​(java.lang.String fileName)
      Maps the given name of a compressed file to the name that the file should have after uncompression.
      boolean isCompressedFilename​(java.lang.String fileName)
      Detects common format suffixes in the given file name.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • compressSuffix

        private final java.util.Map<java.lang.String,​java.lang.String> compressSuffix
        Map from common file name suffixes to the suffixes that identify compressed versions of those file types. For example: from ".tar" to ".tgz".
      • uncompressSuffix

        private final java.util.Map<java.lang.String,​java.lang.String> 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.

      • longestCompressedSuffix

        private final int longestCompressedSuffix
        Length of the longest compressed suffix.
      • shortestCompressedSuffix

        private final int shortestCompressedSuffix
        Length of the shortest compressed suffix.
      • longestUncompressedSuffix

        private final int longestUncompressedSuffix
        Length of the longest uncompressed suffix.
      • shortestUncompressedSuffix

        private final int shortestUncompressedSuffix
        Length of the shortest uncompressed suffix longer than the empty string.
      • defaultExtension

        private final java.lang.String defaultExtension
        The format's default extension.
    • Constructor Detail

      • FileNameUtil

        public FileNameUtil​(java.util.Map<java.lang.String,​java.lang.String> uncompressSuffix,
                            java.lang.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 Detail

      • isCompressedFilename

        public boolean isCompressedFilename​(java.lang.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
      • getUncompressedFilename

        public java.lang.String getUncompressedFilename​(java.lang.String fileName)
        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
      • getCompressedFilename

        public java.lang.String getCompressedFilename​(java.lang.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