mirror of
https://github.com/ysoftdevs/DependencyCheck.git
synced 2026-03-25 18:41:44 +01:00
Simplified getFileExtension by leveraging commons-io. Also cut a line from delete.
This commit is contained in:
@@ -17,6 +17,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.owasp.dependencycheck.utils;
|
package org.owasp.dependencycheck.utils;
|
||||||
|
|
||||||
|
import org.apache.commons.io.FilenameUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
@@ -58,12 +59,8 @@ public final class FileUtils {
|
|||||||
* @return the file extension.
|
* @return the file extension.
|
||||||
*/
|
*/
|
||||||
public static String getFileExtension(String fileName) {
|
public static String getFileExtension(String fileName) {
|
||||||
String ret = null;
|
final String fileExt = FilenameUtils.getExtension(fileName);
|
||||||
final int pos = fileName.lastIndexOf(".");
|
return null != fileExt ? fileExt.toLowerCase() : null;
|
||||||
if (pos >= 0) {
|
|
||||||
ret = fileName.substring(pos + 1).toLowerCase();
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -73,9 +70,8 @@ public final class FileUtils {
|
|||||||
* @return true if the file was deleted successfully, otherwise false
|
* @return true if the file was deleted successfully, otherwise false
|
||||||
*/
|
*/
|
||||||
public static boolean delete(File file) {
|
public static boolean delete(File file) {
|
||||||
boolean success = true;
|
final boolean success = org.apache.commons.io.FileUtils.deleteQuietly(file);
|
||||||
if (!org.apache.commons.io.FileUtils.deleteQuietly(file)) {
|
if (!success) {
|
||||||
success = false;
|
|
||||||
LOGGER.debug("Failed to delete file: {}; attempting to delete on exit.", file.getPath());
|
LOGGER.debug("Failed to delete file: {}; attempting to delete on exit.", file.getPath());
|
||||||
file.deleteOnExit();
|
file.deleteOnExit();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user