This is an automated email from the ASF dual-hosted git repository. ggregory pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-compress.git
commit 6c20f8b1226cc7dd55bae98b224bb87795390b75 Author: Gary Gregory <garydgreg...@gmail.com> AuthorDate: Thu Oct 19 11:14:36 2023 -0400 Add FileNameUtil.getCompressedFileName(String) and deprecate getCompressedFilename(String) - Add FileNameUtil.getUncompressedFileName(String) and deprecate getUncompressedFilename(String) - Add FileNameUtil.isCompressedFileName(String) and deprecate isCompressedFilename(String) --- src/changes/changes.xml | 3 ++ .../commons/compress/compressors/FileNameUtil.java | 52 ++++++++++++++++++++++ .../compress/compressors/bzip2/BZip2Utils.java | 6 +-- .../compress/compressors/gzip/GzipUtils.java | 6 +-- .../compress/compressors/lzma/LZMAUtils.java | 6 +-- .../commons/compress/compressors/xz/XZUtils.java | 6 +-- 6 files changed, 67 insertions(+), 12 deletions(-) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index ada37ee8..a71ea082 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -48,6 +48,9 @@ The <action> type attribute can be add,update,fix,remove. <!-- ADD --> <action type="add" dev="ggregory" due-to="Gary Gregory">Add GzipParameters.getFileName() and deprecate getFilename().</action> <action type="add" dev="ggregory" due-to="Gary Gregory">Add GzipParameters.setFileName(String) and deprecate setFilename(String).</action> + <action type="add" dev="ggregory" due-to="Gary Gregory">Add FileNameUtil.getCompressedFileName(String) and deprecate getCompressedFilename(String).</action> + <action type="add" dev="ggregory" due-to="Gary Gregory">Add FileNameUtil.getUncompressedFileName(String) and deprecate getUncompressedFilename(String).</action> + <action type="add" dev="ggregory" due-to="Gary Gregory">Add FileNameUtil.isCompressedFileName(String) and deprecate isCompressedFilename(String).</action> <!-- FIX --> <!-- UPDATE --> <action type="update" dev="ggregory" due-to="Dependabot">Bump org.slf4j:slf4j-api from 2.0.8 to 2.0.9 #413.</action> diff --git a/src/main/java/org/apache/commons/compress/compressors/FileNameUtil.java b/src/main/java/org/apache/commons/compress/compressors/FileNameUtil.java index 1dfd9fee..66b4eb0a 100644 --- a/src/main/java/org/apache/commons/compress/compressors/FileNameUtil.java +++ b/src/main/java/org/apache/commons/compress/compressors/FileNameUtil.java @@ -131,8 +131,26 @@ public class FileNameUtil { * * @param fileName name of a file * @return name of the corresponding compressed file + * @deprecated Use {@link #getCompressedFileName(String)}. */ + @Deprecated public String getCompressedFilename(final String fileName) { + return getCompressedFileName(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. + * + * @param fileName name of a file + * @return name of the corresponding compressed file + * @since 1.25.0 + */ + public String getCompressedFileName(final String fileName) { final String lower = fileName.toLowerCase(Locale.ENGLISH); final int n = lower.length(); for (int i = shortestUncompressedSuffix; @@ -158,8 +176,28 @@ public class FileNameUtil { * * @param fileName name of a file * @return name of the corresponding uncompressed file + * @deprecated Use {@link #getUncompressedFileName(String)}. */ + @Deprecated public String getUncompressedFilename(final String fileName) { + return getUncompressedFileName(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. + * + * @param fileName name of a file + * @return name of the corresponding uncompressed file + * @since 1.25.0 + */ + public String getUncompressedFileName(final String fileName) { final String lower = fileName.toLowerCase(Locale.ENGLISH); final int n = lower.length(); for (int i = shortestCompressedSuffix; @@ -178,8 +216,22 @@ public class FileNameUtil { * @param fileName name of a file * @return {@code true} if the file name has a common format suffix, * {@code false} otherwise + * @deprecated Use {@link #isCompressedFileName(String)}. */ + @Deprecated public boolean isCompressedFilename(final String fileName) { + return isCompressedFileName(fileName); + } + + /** + * Detects common format suffixes in the given file name. + * + * @param fileName name of a file + * @return {@code true} if the file name has a common format suffix, + * {@code false} otherwise + * @since 1.25.0 + */ + public boolean isCompressedFileName(final String fileName) { final String lower = fileName.toLowerCase(Locale.ENGLISH); final int n = lower.length(); for (int i = shortestCompressedSuffix; diff --git a/src/main/java/org/apache/commons/compress/compressors/bzip2/BZip2Utils.java b/src/main/java/org/apache/commons/compress/compressors/bzip2/BZip2Utils.java index 7235961f..2884d229 100644 --- a/src/main/java/org/apache/commons/compress/compressors/bzip2/BZip2Utils.java +++ b/src/main/java/org/apache/commons/compress/compressors/bzip2/BZip2Utils.java @@ -56,7 +56,7 @@ public abstract class BZip2Utils { * @return name of the corresponding compressed file */ public static String getCompressedFilename(final String fileName) { - return fileNameUtil.getCompressedFilename(fileName); + return fileNameUtil.getCompressedFileName(fileName); } /** @@ -73,7 +73,7 @@ public abstract class BZip2Utils { * @return name of the corresponding uncompressed file */ public static String getUncompressedFilename(final String fileName) { - return fileNameUtil.getUncompressedFilename(fileName); + return fileNameUtil.getUncompressedFileName(fileName); } /** @@ -84,7 +84,7 @@ public abstract class BZip2Utils { * {@code false} otherwise */ public static boolean isCompressedFilename(final String fileName) { - return fileNameUtil.isCompressedFilename(fileName); + return fileNameUtil.isCompressedFileName(fileName); } /** Private constructor to prevent instantiation of this utility class. */ diff --git a/src/main/java/org/apache/commons/compress/compressors/gzip/GzipUtils.java b/src/main/java/org/apache/commons/compress/compressors/gzip/GzipUtils.java index 013adae2..a73b8a4a 100644 --- a/src/main/java/org/apache/commons/compress/compressors/gzip/GzipUtils.java +++ b/src/main/java/org/apache/commons/compress/compressors/gzip/GzipUtils.java @@ -70,7 +70,7 @@ public class GzipUtils { * @return name of the corresponding compressed file */ public static String getCompressedFilename(final String fileName) { - return fileNameUtil.getCompressedFilename(fileName); + return fileNameUtil.getCompressedFileName(fileName); } /** @@ -87,7 +87,7 @@ public class GzipUtils { * @return name of the corresponding uncompressed file */ public static String getUncompressedFilename(final String fileName) { - return fileNameUtil.getUncompressedFilename(fileName); + return fileNameUtil.getUncompressedFileName(fileName); } /** @@ -98,7 +98,7 @@ public class GzipUtils { * {@code false} otherwise */ public static boolean isCompressedFilename(final String fileName) { - return fileNameUtil.isCompressedFilename(fileName); + return fileNameUtil.isCompressedFileName(fileName); } /** Private constructor to prevent instantiation of this utility class. */ diff --git a/src/main/java/org/apache/commons/compress/compressors/lzma/LZMAUtils.java b/src/main/java/org/apache/commons/compress/compressors/lzma/LZMAUtils.java index bedefa54..7e5ebd41 100644 --- a/src/main/java/org/apache/commons/compress/compressors/lzma/LZMAUtils.java +++ b/src/main/java/org/apache/commons/compress/compressors/lzma/LZMAUtils.java @@ -68,7 +68,7 @@ public class LZMAUtils { * @return name of the corresponding compressed file */ public static String getCompressedFilename(final String fileName) { - return fileNameUtil.getCompressedFilename(fileName); + return fileNameUtil.getCompressedFileName(fileName); } /** @@ -82,7 +82,7 @@ public class LZMAUtils { * @return name of the corresponding uncompressed file */ public static String getUncompressedFilename(final String fileName) { - return fileNameUtil.getUncompressedFilename(fileName); + return fileNameUtil.getUncompressedFileName(fileName); } private static boolean internalIsLZMACompressionAvailable() { @@ -102,7 +102,7 @@ public class LZMAUtils { * {@code false} otherwise */ public static boolean isCompressedFilename(final String fileName) { - return fileNameUtil.isCompressedFilename(fileName); + return fileNameUtil.isCompressedFileName(fileName); } /** diff --git a/src/main/java/org/apache/commons/compress/compressors/xz/XZUtils.java b/src/main/java/org/apache/commons/compress/compressors/xz/XZUtils.java index 3429c0e2..54bf52f9 100644 --- a/src/main/java/org/apache/commons/compress/compressors/xz/XZUtils.java +++ b/src/main/java/org/apache/commons/compress/compressors/xz/XZUtils.java @@ -76,7 +76,7 @@ public class XZUtils { * @return name of the corresponding compressed file */ public static String getCompressedFilename(final String fileName) { - return fileNameUtil.getCompressedFilename(fileName); + return fileNameUtil.getCompressedFileName(fileName); } /** @@ -93,7 +93,7 @@ public class XZUtils { * @return name of the corresponding uncompressed file */ public static String getUncompressedFilename(final String fileName) { - return fileNameUtil.getUncompressedFilename(fileName); + return fileNameUtil.getUncompressedFileName(fileName); } private static boolean internalIsXZCompressionAvailable() { @@ -113,7 +113,7 @@ public class XZUtils { * {@code false} otherwise */ public static boolean isCompressedFilename(final String fileName) { - return fileNameUtil.isCompressedFilename(fileName); + return fileNameUtil.isCompressedFileName(fileName); } /**