Class FileUtil

java.lang.Object
com.brightcove.player.util.FileUtil

public class FileUtil extends Object
Provides utility methods to work files and folders.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    Provides strict mode equivalents to methods in FileUtil.
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    Closes the given Closeable object ignoring any resulting exceptions.
    static boolean
    delete(File path)
    Deletes a file or folder, even if the folder is not empty.
    static boolean
    exists(String path)
    Checks if specified path points to a file or directory that exists on the local filesystem.
    static File
    getExternalDirectory(android.content.Context context, String folderType, String name)
    Gets the path to a directory on the primary shared/external storage device where the application can place persistent files it owns.
    static String
    Gets the file name from a URL string.
    static boolean
    Checks if the URI has a file scheme.
    static boolean
    Checks if specified path points to a directory that exists on the local filesystem.
    static boolean
    isFile(String path)
    Checks if specified path points to a file that exists on the local filesystem.
    static boolean
    Checks if the specified path is valid, meaning it exists or can be created, has read permissions and has write permissions
    static File
    Checks if the specified path is a directory that can be read from and written into.
    static void
    saveInputStream(File target, InputStream source)
    Utility method to save the input stream to the file provided.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • makeReadWriteDirectory

      @NonNull public static File makeReadWriteDirectory(@Nullable File path)
      Checks if the specified path is a directory that can be read from and written into. If the directory does not exist, then this method will try to create a readable/writable directory.
      Parameters:
      path - the path to check/create.
      Returns:
      reference to the validated path.
      Throws:
      IllegalArgumentException - if the download path is invalid or if the download path does not have read or write permissions.
    • isFileValid

      public static boolean isFileValid(@Nullable File path)
      Checks if the specified path is valid, meaning it exists or can be created, has read permissions and has write permissions
      Parameters:
      path - File to check if is valid.
      Returns:
      true if the path is valid.
    • getExternalDirectory

      @NonNull public static File getExternalDirectory(@NonNull android.content.Context context, @Nullable String folderType, @Nullable String name)

      Gets the path to a directory on the primary shared/external storage device where the application can place persistent files it owns. These files are internal to the applications, and not typically visible to the user as media.

      Please note that this method will neither check if selected directory exists nor whether it is readable or writable.

      Parameters:
      context - the context
      folderType - the type of files directory to return. May be null for the root of the files directory or one of the following constants for a subdirectory: Environment.DIRECTORY_MUSIC, Environment.DIRECTORY_PODCASTS, Environment.DIRECTORY_RINGTONES, Environment.DIRECTORY_ALARMS, Environment.DIRECTORY_NOTIFICATIONS, Environment.DIRECTORY_PICTURES, or Environment.DIRECTORY_MOVIES.
      name - an optional subfolder name within the selected folder type.
      Returns:
      the path to the selected directory.
      See Also:
    • delete

      public static boolean delete(@NonNull File path)
      Deletes a file or folder, even if the folder is not empty.
      Parameters:
      path - the path to be deleted.
      Returns:
      false if the file or folder was found, but could not be deleted.
    • getFileName

      public static String getFileName(String url)
      Gets the file name from a URL string.
      Parameters:
      url - the url string
      Returns:
      the file name
    • closeQuietly

      public static void closeQuietly(@Nullable Closeable closeable)
      Closes the given Closeable object ignoring any resulting exceptions.
      Parameters:
      closeable - the object to be closed.
    • saveInputStream

      public static void saveInputStream(@NonNull File target, @NonNull InputStream source) throws IOException
      Utility method to save the input stream to the file provided.
      Parameters:
      source - the input stream
      target - the file to save the input stream
      Throws:
      IOException - if the stream cannot be saved.
    • isFile

      public static boolean isFile(@Nullable String path)
      Checks if specified path points to a file that exists on the local filesystem.
      Parameters:
      path - the string path to be checked.
      Returns:
      true is the path points to a local file.
    • isDirectory

      public static boolean isDirectory(@Nullable String path)
      Checks if specified path points to a directory that exists on the local filesystem.
      Parameters:
      path - the string path to be checked.
      Returns:
      true is the path points to a local file.
    • exists

      public static boolean exists(@Nullable String path)
      Checks if specified path points to a file or directory that exists on the local filesystem.
      Parameters:
      path - the string path to be checked.
      Returns:
      true is the path points to a local file or directory.
    • hasFileScheme

      public static boolean hasFileScheme(URI uri)
      Checks if the URI has a file scheme.
      Parameters:
      uri - the URI object to check.
      Returns:
      true if the uri contains a file scheme, false otherwise.