Class XZUtils
- java.lang.Object
-
- org.apache.commons.compress.compressors.xz.XZUtils
-
public class XZUtils extends java.lang.Object
Utility code for the xz compression format.- Since:
- 1.4
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static class
XZUtils.CachedAvailability
-
Field Summary
Fields Modifier and Type Field Description private static XZUtils.CachedAvailability
cachedXZAvailability
private static FileNameUtil
fileNameUtil
private static byte[]
HEADER_MAGIC
XZ Header Magic Bytes begin a XZ file.
-
Constructor Summary
Constructors Modifier Constructor Description private
XZUtils()
Private constructor to prevent instantiation of this utility class.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description (package private) static XZUtils.CachedAvailability
getCachedXZAvailability()
static java.lang.String
getCompressedFilename(java.lang.String fileName)
Maps the given file name to the name that the file should have after compression with xz.static java.lang.String
getUncompressedFilename(java.lang.String fileName)
Maps the given name of a xz-compressed file to the name that the file should have after uncompression.private static boolean
internalIsXZCompressionAvailable()
static boolean
isCompressedFilename(java.lang.String fileName)
Detects common xz suffixes in the given file name.static boolean
isXZCompressionAvailable()
Are the classes required to support XZ compression available?static boolean
matches(byte[] signature, int length)
Checks if the signature matches what is expected for a .xz file.static void
setCacheXZAvailablity(boolean doCache)
Whether to cache the result of the XZ for Java check.
-
-
-
Field Detail
-
fileNameUtil
private static final FileNameUtil fileNameUtil
-
HEADER_MAGIC
private static final byte[] HEADER_MAGIC
XZ Header Magic Bytes begin a XZ file.This is a copy of
org.tukaani.xz.XZ.HEADER_MAGIC
in XZ for Java version 1.5.
-
cachedXZAvailability
private static volatile XZUtils.CachedAvailability cachedXZAvailability
-
-
Method Detail
-
matches
public static boolean matches(byte[] signature, int length)
Checks if the signature matches what is expected for a .xz file.This is more or less a copy of the version found in
XZCompressorInputStream
but doesn't depend on the presence of XZ for Java.- Parameters:
signature
- the bytes to checklength
- the number of bytes to check- Returns:
- true if signature matches the .xz magic bytes, false otherwise
- Since:
- 1.9
-
isXZCompressionAvailable
public static boolean isXZCompressionAvailable()
Are the classes required to support XZ compression available?- Returns:
- true if the classes required to support XZ compression are available
- Since:
- 1.5
-
internalIsXZCompressionAvailable
private static boolean internalIsXZCompressionAvailable()
-
isCompressedFilename
public static boolean isCompressedFilename(java.lang.String fileName)
Detects common xz suffixes in the given file name.- Parameters:
fileName
- name of a file- Returns:
true
if the file name has a common xz suffix,false
otherwise
-
getUncompressedFilename
public static java.lang.String getUncompressedFilename(java.lang.String fileName)
Maps the given name of a xz-compressed file to the name that the file should have after uncompression. Commonly used file type specific suffixes like ".txz" are automatically detected and correctly mapped. For example the name "package.txz" is mapped to "package.tar". And any file names with the generic ".xz" suffix (or any other generic xz suffix) is mapped to a name without that suffix. If no xz 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 static java.lang.String getCompressedFilename(java.lang.String fileName)
Maps the given file name to the name that the file should have after compression with xz. 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.txz". If no custom mapping is applicable, then the default ".xz" suffix is appended to the file name.- Parameters:
fileName
- name of a file- Returns:
- name of the corresponding compressed file
-
setCacheXZAvailablity
public static void setCacheXZAvailablity(boolean doCache)
Whether to cache the result of the XZ for Java check.This defaults to
false
in an OSGi environment andtrue
otherwise.- Parameters:
doCache
- whether to cache the result- Since:
- 1.9
-
getCachedXZAvailability
static XZUtils.CachedAvailability getCachedXZAvailability()
-
-