Class FileUtils

java.lang.Object
org.owasp.dependencycheck.utils.FileUtils

public final class FileUtils extends Object
A collection of utilities for processing information about files.
Author:
Jeremy Long
  • Method Details

    • getFileExtension

      public static @Nullable String getFileExtension(@NonNull 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 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

      public static @NonNull File createTempDirectory(@Nullable File base) throws IOException
      Creates a unique temporary directory in the given directory.
      Parameters:
      base - the base directory to create a temporary directory within
      Returns:
      the temporary directory
      Throws:
      IOException - thrown when a directory cannot be created within the base directory
    • getBitBucket

      public static @NonNull 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 Closeable closeable)
      Close the given Closeable instance, ignoring nulls, and logging any thrown IOException.
      Parameters:
      closeable - to be closed
    • getResourceAsStream

      public static InputStream getResourceAsStream(@NonNull String resource) throws FileNotFoundException
      Gets the InputStream for this resource.
      Parameters:
      resource - path
      Returns:
      the input stream for the given resource
      Throws:
      FileNotFoundException - if the file could not be found
    • getResourceAsFile

      public static File getResourceAsFile(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