Top Description Fields Constructors Methods
org.apache.commons.compress.compressors

public Class FileNameUtil

extends Object
Class Inheritance
Imports
java.util.Collections, .HashMap, .Locale, .Map

File name mapping code for the compression formats.
Since
1.4

Field Summary

Modifier and TypeField and Description
private final Map<String, String>
compressSuffix

Map from common file name suffixes to the suffixes that identify compressed versions of those file types.

private final String
defaultExtension

The format's default extension.

private final int
longestCompressedSuffix

Length of the longest compressed suffix.

private final int
longestUncompressedSuffix

Length of the longest uncompressed suffix.

private final int
shortestCompressedSuffix

Length of the shortest compressed suffix.

private final int
shortestUncompressedSuffix

Length of the shortest uncompressed suffix longer than the empty string.

private final Map<String, String>
uncompressSuffix

Map from common file name suffixes of compressed files to the corresponding suffixes of uncompressed files.

Constructor Summary

AccessConstructor and Description
public
FileNameUtil(final Map<String, String>
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.
uncompressSuffix
,
final String
the format's default extension like ".gz"
defaultExtension
)

sets up the utility with a map of known compressed to uncompressed suffix mappings and the default extension of the format.

Method Summary

Modifier and TypeMethod and Description
public String

Returns:

name of the corresponding compressed file
getCompressedFilename
(final String
name of a file
fileName
)

Maps the given file name to the name that the file should have after compression.
public String

Returns:

name of the corresponding compressed file
getCompressedFileName
(final String
name of a file
fileName
)

Maps the given file name to the name that the file should have after compression.

public String

Returns:

name of the corresponding uncompressed file
getUncompressedFilename
(final String
name of a file
fileName
)

Maps the given name of a compressed file to the name that the file should have after uncompression.
public String

Returns:

name of the corresponding uncompressed file
getUncompressedFileName
(final String
name of a file
fileName
)

Maps the given name of a compressed file to the name that the file should have after uncompression.

public boolean

Returns:

true if the file name has a common format suffix, false otherwise
isCompressedFilename
(final String
name of a file
fileName
)

Detects common format suffixes in the given file name.
public boolean

Returns:

true if the file name has a common format suffix, false otherwise
isCompressedFileName
(final String
name of a file
fileName
)

Detects common format suffixes in the given file name.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

compressSuffixback to summary
private final Map<String, 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".

defaultExtensionback to summary
private final String defaultExtension

The format's default extension.

longestCompressedSuffixback to summary
private final int longestCompressedSuffix

Length of the longest compressed suffix.

longestUncompressedSuffixback to summary
private final int longestUncompressedSuffix

Length of the longest uncompressed suffix.

shortestCompressedSuffixback to summary
private final int shortestCompressedSuffix

Length of the shortest compressed suffix.

shortestUncompressedSuffixback to summary
private final int shortestUncompressedSuffix

Length of the shortest uncompressed suffix longer than the empty string.

uncompressSuffixback to summary
private final Map<String, 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.

Constructor Detail

FileNameUtilback to summary
public FileNameUtil(final Map<String, String> uncompressSuffix, final 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<String, String>

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:String

the format's default extension like ".gz"

Method Detail

getCompressedFilenameback to summary
public String getCompressedFilename(final 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:String

name of a file

Returns:String

name of the corresponding compressed file

Annotations
@Deprecated
getCompressedFileNameback to summary
public String getCompressedFileName(final 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:String

name of a file

Returns:String

name of the corresponding compressed file

Since
1.25.0
getUncompressedFilenameback to summary
public String getUncompressedFilename(final 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:String

name of a file

Returns:String

name of the corresponding uncompressed file

Annotations
@Deprecated
getUncompressedFileNameback to summary
public String getUncompressedFileName(final 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:String

name of a file

Returns:String

name of the corresponding uncompressed file

Since
1.25.0
isCompressedFilenameback to summary
public boolean isCompressedFilename(final String fileName)

Detects common format suffixes in the given file name.

Parameters
fileName:String

name of a file

Returns:boolean

true if the file name has a common format suffix, false otherwise

Annotations
@Deprecated
isCompressedFileNameback to summary
public boolean isCompressedFileName(final String fileName)

Detects common format suffixes in the given file name.

Parameters
fileName:String

name of a file

Returns:boolean

true if the file name has a common format suffix, false otherwise

Since
1.25.0