Package com.brightcove.player.util
Class FileUtil
java.lang.Object
com.brightcove.player.util.FileUtil
Provides utility methods to work files and folders.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Provides strict mode equivalents to methods inFileUtil
. -
Method Summary
Modifier and TypeMethodDescriptionstatic void
closeQuietly
(Closeable closeable) Closes the givenCloseable
object ignoring any resulting exceptions.static boolean
Deletes a file or folder, even if the folder is not empty.static boolean
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
getFileName
(String url) Gets the file name from a URL string.static boolean
hasFileScheme
(URI uri) Checks if the URI has a file scheme.static boolean
isDirectory
(String path) Checks if specified path points to a directory that exists on the local filesystem.static boolean
Checks if specified path points to a file that exists on the local filesystem.static boolean
isFileValid
(File path) Checks if the specified path is valid, meaning it exists or can be created, has read permissions and has write permissionsstatic File
makeReadWriteDirectory
(File path) 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.
-
Method Details
-
makeReadWriteDirectory
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
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 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:
-
delete
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
Gets the file name from a URL string.- Parameters:
url
- the url string- Returns:
- the file name
-
closeQuietly
Closes the givenCloseable
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 streamtarget
- the file to save the input stream- Throws:
IOException
- if the stream cannot be saved.
-
isFile
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
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
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
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.
-