Package com.brightcove.player.util
Class FileUtil
- java.lang.Object
-
- com.brightcove.player.util.FileUtil
-
public class FileUtil extends java.lang.ObjectProvides utility methods to work files and folders.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classFileUtil.StrictModeProvides strict mode equivalents to methods inFileUtil.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidcloseQuietly(java.io.Closeable closeable)Closes the givenCloseableobject ignoring any resulting exceptions.static booleandelete(java.io.File path)Deletes a file or folder, even if the folder is not empty.static booleanexists(java.lang.String path)Checks if specified path points to a file or directory that exists on the local filesystem.static java.io.FilegetExternalDirectory(android.content.Context context, java.lang.String folderType, java.lang.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 java.lang.StringgetFileName(java.lang.String url)Gets the file name from a URL string.static booleanhasFileScheme(java.net.URI uri)Checks if the URI has a file scheme.static booleanisDirectory(java.lang.String path)Checks if specified path points to a directory that exists on the local filesystem.static booleanisFile(java.lang.String path)Checks if specified path points to a file that exists on the local filesystem.static booleanisFileValid(java.io.File path)Checks if the specified path is valid, meaning it exists or can be created, has read permissions and has write permissionsstatic java.io.FilemakeReadWriteDirectory(java.io.File path)Checks if the specified path is a directory that can be read from and written into.static voidsaveInputStream(java.io.File target, java.io.InputStream source)Utility method to save the input stream to the file provided.
-
-
-
Method Detail
-
makeReadWriteDirectory
@NonNull public static java.io.File makeReadWriteDirectory(@Nullable java.io.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:
java.lang.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 java.io.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 java.io.File getExternalDirectory(@NonNull android.content.Context context, @Nullable java.lang.String folderType, @Nullable java.lang.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 contextfolderType- 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, orEnvironment.DIRECTORY_MOVIES.name- an optional subfolder name within the selected folder type.- Returns:
- the path to the selected directory.
- See Also:
makeReadWriteDirectory(File)
-
delete
public static boolean delete(@NonNull java.io.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 java.lang.String getFileName(java.lang.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 java.io.Closeable closeable)Closes the givenCloseableobject ignoring any resulting exceptions.- Parameters:
closeable- the object to be closed.
-
saveInputStream
public static void saveInputStream(@NonNull java.io.File target, @NonNull java.io.InputStream source) throws java.io.IOExceptionUtility method to save the input stream to the file provided.- Parameters:
source- the input streamtarget- the file to save the input stream- Throws:
java.io.IOException- if the stream cannot be saved.
-
isFile
public static boolean isFile(@Nullable java.lang.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 java.lang.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 java.lang.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(java.net.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.
-
-