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


The following commit(s) were added to refs/heads/master by this push:
     new 6ac5f8015 Reuse FilenameUtils
6ac5f8015 is described below

commit 6ac5f80156e9aaa8666c97b5bde0902be0fa7dd6
Author: Gary Gregory <[email protected]>
AuthorDate: Fri Dec 22 22:34:00 2023 -0500

    Reuse FilenameUtils
---
 .../org/apache/commons/compress/utils/FileNameUtils.java   | 14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)

diff --git a/src/main/java/org/apache/commons/compress/utils/FileNameUtils.java 
b/src/main/java/org/apache/commons/compress/utils/FileNameUtils.java
index da01ee598..c107e89ed 100644
--- a/src/main/java/org/apache/commons/compress/utils/FileNameUtils.java
+++ b/src/main/java/org/apache/commons/compress/utils/FileNameUtils.java
@@ -20,6 +20,8 @@ package org.apache.commons.compress.utils;
 import java.io.File;
 import java.nio.file.Path;
 
+import org.apache.commons.io.FilenameUtils;
+
 /**
  * Generic file name utilities.
  *
@@ -32,11 +34,6 @@ public class FileNameUtils {
         return extensionIndex < 0 ? name : name.substring(0, extensionIndex);
     }
 
-    private static String fileNameToExtension(final String name) {
-        final int extensionIndex = name.lastIndexOf('.');
-        return extensionIndex < 0 ? "" : name.substring(extensionIndex + 1);
-    }
-
     /**
      * Gets the base name (i.e. the part up to and not including the last ".") 
of the last path segment of a file name.
      * <p>
@@ -88,7 +85,7 @@ public class FileNameUtils {
             return null;
         }
         final Path fileName = path.getFileName();
-        return fileName != null ? fileNameToExtension(fileName.toString()) : 
null;
+        return fileName != null ? 
FilenameUtils.getExtension(fileName.toString()) : null;
     }
 
     /**
@@ -103,9 +100,6 @@ public class FileNameUtils {
      * @param fileName the name of the file to obtain the extension of.
      */
     public static String getExtension(final String fileName) {
-        if (fileName == null) {
-            return null;
-        }
-        return fileNameToExtension(new File(fileName).getName());
+        return FilenameUtils.getExtension(fileName);
     }
 }

Reply via email to