Update org.apache.commons.io.FilenameUtils.isExtension(String,
String[]) to use var args.
MODIFY
src/changes/changes.xml
src/changes/changes.xml
@@ -71,6 +71,9 @@ The <action> type attribute can be add,update,fix,remove.
<action issue="IO-559" type="fix">
FilenameUtils.normalize now verifies hostname syntax in UNC path.
</action>
+ <action issue="IO-580" dev="ggregory" type="update">
+ Update org.apache.commons.io.FilenameUtils.isExtension(String, String[]) to use var args.
+ </action>
</release>
<release version="2.6" date="2017-10-15" description="Java 7 required, Java 9 supported.">

MODIFY
src/main/java/org/apache/commons/io/FilenameUtils.java
src/main/java/org/apache/commons/io/FilenameUtils.java
@@ -1256,7 +1256,7 @@ public static boolean isExtension(final String fileName, final String extension)
* @return true if the fileName is one of the extensions
* @throws java.lang.IllegalArgumentException if the supplied fileName contains null bytes
*/
- public static boolean isExtension(final String fileName, final String[] extensions) {
+ public static boolean isExtension(final String fileName, final String... extensions) {
if (fileName == null) {
return false;
}

MODIFY
src/test/java/org/apache/commons/io/FilenameUtilsTestCase.java
src/test/java/org/apache/commons/io/FilenameUtilsTestCase.java
@@ -1109,6 +1109,33 @@ public void testIsExtensionArray() {
assertFalse(FilenameUtils.isExtension("a.b\\file.txt", new String[]{"TXT", "RTF"}));
}
+ @Test
+ public void testIsExtensionVarArgs() {
+ assertTrue(FilenameUtils.isExtension("file.txt", "txt"));
+ assertFalse(FilenameUtils.isExtension("file.txt", "rtf"));
+ assertTrue(FilenameUtils.isExtension("file", "rtf", ""));
+ assertTrue(FilenameUtils.isExtension("file.txt", "rtf", "txt"));
+
+ assertTrue(FilenameUtils.isExtension("a/b/file.txt", "txt"));
+ assertFalse(FilenameUtils.isExtension("a/b/file.txt", "rtf"));
+ assertTrue(FilenameUtils.isExtension("a/b/file.txt", "rtf", "txt"));
+
+ assertTrue(FilenameUtils.isExtension("a.b/file.txt", "txt"));
+ assertFalse(FilenameUtils.isExtension("a.b/file.txt", "rtf"));
+ assertTrue(FilenameUtils.isExtension("a.b/file.txt", "rtf", "txt"));
+
+ assertTrue(FilenameUtils.isExtension("a\\b\\file.txt", "txt"));
+ assertFalse(FilenameUtils.isExtension("a\\b\\file.txt", "rtf"));
+ assertTrue(FilenameUtils.isExtension("a\\b\\file.txt", "rtf", "txt"));
+
+ assertTrue(FilenameUtils.isExtension("a.b\\file.txt", "txt"));
+ assertFalse(FilenameUtils.isExtension("a.b\\file.txt", "rtf"));
+ assertTrue(FilenameUtils.isExtension("a.b\\file.txt", "rtf", "txt"));
+
+ assertFalse(FilenameUtils.isExtension("a.b\\file.txt", "TXT"));
+ assertFalse(FilenameUtils.isExtension("a.b\\file.txt", "TXT", "RTF"));
+ }
+
@Test
public void testIsExtensionCollection() {
assertFalse(FilenameUtils.isExtension(null, (Collection<String>) null));

[IO-580] Update org.apache.commons.io.FilenameUtils.isExtension(String,
String[]) to use var args.