Package org.owasp.dependencycheck.utils
Class FileUtils
- java.lang.Object
-
- org.owasp.dependencycheck.utils.FileUtils
-
public final class FileUtils extends java.lang.ObjectA collection of utilities for processing information about files.- Author:
- Jeremy Long
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidclose(@Nullable java.io.Closeable closeable)Close the givenCloseableinstance, ignoring nulls, and logging any thrownIOException.static @NotNull java.io.FilecreateTempDirectory(@Nullable java.io.File base)Creates a unique temporary directory in the given directory.static booleandelete(@Nullable java.io.File file)Deletes a file.static @NotNull java.lang.StringgetBitBucket()Return the bit bucket for the OS.static @Nullable java.lang.StringgetFileExtension(@NotNull java.lang.String fileName)Returns the (lowercase) file extension for a specified file.static java.io.FilegetResourceAsFile(java.lang.String resource)Returns a File object for the given resource.static @Nullable java.io.InputStreamgetResourceAsStream(@NotNull java.lang.String resource)Gets theInputStreamfor this resource.
-
-
-
Method Detail
-
getFileExtension
@Nullable public static @Nullable java.lang.String getFileExtension(@NotNull @NotNull java.lang.String fileName)Returns the (lowercase) file extension for a specified file.- Parameters:
fileName- the file name to retrieve the file extension from.- Returns:
- the file extension.
-
delete
public static boolean delete(@Nullable @Nullable java.io.File file)Deletes a file. If the File is a directory it will recursively delete the contents.- Parameters:
file- the File to delete- Returns:
- true if the file was deleted successfully, otherwise false
-
createTempDirectory
@NotNull public static @NotNull java.io.File createTempDirectory(@Nullable @Nullable java.io.File base) throws java.io.IOExceptionCreates a unique temporary directory in the given directory.- Parameters:
base- the base directory to create a temporary directory within- Returns:
- the temporary directory
- Throws:
java.io.IOException- thrown when a directory cannot be created within the base directory
-
getBitBucket
@NotNull public static @NotNull java.lang.String getBitBucket()
Return the bit bucket for the OS. '/dev/null' for Unix and 'NUL' for Windows- Returns:
- a String containing the bit bucket
-
close
public static void close(@Nullable @Nullable java.io.Closeable closeable)Close the givenCloseableinstance, ignoring nulls, and logging any thrownIOException.- Parameters:
closeable- to be closed
-
getResourceAsStream
@Nullable public static @Nullable java.io.InputStream getResourceAsStream(@NotNull @NotNull java.lang.String resource) throws java.io.FileNotFoundExceptionGets theInputStreamfor this resource.- Parameters:
resource- path- Returns:
- the input stream for the given resource
- Throws:
java.io.FileNotFoundException- if the file could not be found
-
getResourceAsFile
public static java.io.File getResourceAsFile(java.lang.String resource)
Returns a File object for the given resource. The resource is attempted to be loaded from the class loader.- Parameters:
resource- path- Returns:
- the file reference for the resource
-
-