Simplified getFileExtension by leveraging commons-io. Also cut a line from delete.

This commit is contained in:
Anthony Whitford
2015-10-13 23:50:41 -07:00
parent 2f518dacfc
commit f121430a5d

View File

@@ -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();
} }