Package com.mku.android.file
Class AndroidFile
java.lang.Object
com.mku.android.file.AndroidFile
- All Implemented Interfaces:
IRealFile
Implementation of the IRealFile for Android using Storage Access Framework that supports read/write to external SD cards.
This class is used by the AndroidDrive implementation so you can use SalmonFile wrapper transparently
-
Field Summary
Fields inherited from interface com.mku.file.IRealFile
autoRename
-
Constructor Summary
ConstructorDescriptionAndroidFile
(DocumentFile documentFile, Context context) Construct an AndroidFile wrapper from an Android DocumentFile. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Clear the cacheCopy this file to another directory.Copy this file to another directory.Copy this file to another directory.createDirectory
(String dirName) Create the directory with the name provided under this directory.createFile
(String filename) Create an empty file with the provided name.boolean
delete()
Delete this file.boolean
exists()
True if file exists.Get the absolute path on the physical drive.Get the base name of this file.Get a child file in this directory.int
Get the count of files and subdirectoriesParcelFileDescriptor
getFileDescriptor
(String mode) Get a file descriptor corresponding to this file.Get a stream for reading.Get a stream for writing.Get the parent directory.getPath()
Get the path.boolean
True if it is a directory.boolean
isFile()
True if it is a file.long
Get the last modified date in milliseconds.long
length()
Get the size of the file.List files and directories.boolean
mkdir()
Create this directory.Move this file to another directory.Move this file to another directory.Move this file to another directory.boolean
Rename file.toString()
Returns a string representation of this objectMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface com.mku.file.IRealFile
copyRecursively, copyRecursively, deleteRecursively, moveRecursively, moveRecursively
-
Constructor Details
-
AndroidFile
public AndroidFile(DocumentFile documentFile, Context context) Construct an AndroidFile wrapper from an Android DocumentFile.- Parameters:
documentFile
- The Android DocumentFile that will be associated tocontext
- Android Context
-
-
Method Details
-
createDirectory
Description copied from interface:IRealFile
Create the directory with the name provided under this directory.- Specified by:
createDirectory
in interfaceIRealFile
- Parameters:
dirName
- Directory name.- Returns:
- The newly created directory.
-
createFile
Description copied from interface:IRealFile
Create an empty file with the provided name.- Specified by:
createFile
in interfaceIRealFile
- Parameters:
filename
- The name for the new file.- Returns:
- The newly create file.
-
delete
public boolean delete()Delete this file. -
exists
public boolean exists()True if file exists. -
getAbsolutePath
Get the absolute path on the physical drive.- Specified by:
getAbsolutePath
in interfaceIRealFile
- Returns:
- The absolute path
-
getBaseName
Get the base name of this file.- Specified by:
getBaseName
in interfaceIRealFile
- Returns:
- The base name
-
getInputStream
Get a stream for reading.- Specified by:
getInputStream
in interfaceIRealFile
- Returns:
- The input stream
- Throws:
FileNotFoundException
- Thrown if file is not found
-
getOutputStream
Get a stream for writing.- Specified by:
getOutputStream
in interfaceIRealFile
- Returns:
- The output stream
- Throws:
FileNotFoundException
- Thrown if file not found
-
getParent
Get the parent directory. -
getPath
Get the path. -
isDirectory
public boolean isDirectory()True if it is a directory.- Specified by:
isDirectory
in interfaceIRealFile
- Returns:
- True if directory
-
isFile
public boolean isFile()True if it is a file. -
lastModified
public long lastModified()Get the last modified date in milliseconds.- Specified by:
lastModified
in interfaceIRealFile
- Returns:
- Last modified date in milliseconds
-
length
public long length()Get the size of the file. -
getChildrenCount
public int getChildrenCount()Get the count of files and subdirectories- Specified by:
getChildrenCount
in interfaceIRealFile
- Returns:
- The children count
-
listFiles
List files and directories. -
move
Move this file to another directory.- Specified by:
move
in interfaceIRealFile
- Parameters:
newDir
- The target directory.- Returns:
- The moved file
- Throws:
IOException
- Thrown if error during IO
-
move
Move this file to another directory.- Specified by:
move
in interfaceIRealFile
- Parameters:
newDir
- The target directory.newName
- The new filename- Returns:
- The moved file
- Throws:
IOException
- Thrown if error during IO
-
move
public IRealFile move(IRealFile newDir, String newName, BiConsumer<Long, Long> progressListener) throws IOExceptionMove this file to another directory.- Specified by:
move
in interfaceIRealFile
- Parameters:
newDir
- The target directory.progressListener
- Observer to notify of the move progress.newName
- The new filename.- Returns:
- The moved file
- Throws:
IOException
- Thrown if error during IO
-
copy
Copy this file to another directory.- Specified by:
copy
in interfaceIRealFile
- Parameters:
newDir
- The target directory.- Returns:
- The new file
- Throws:
IOException
- Thrown if error during IO
-
copy
Copy this file to another directory.- Specified by:
copy
in interfaceIRealFile
- Parameters:
newDir
- The target directory.newName
- The new filename- Returns:
- The new file
- Throws:
IOException
- Thrown if error during IO
-
copy
public IRealFile copy(IRealFile newDir, String newName, BiConsumer<Long, Long> progressListener) throws IOExceptionCopy this file to another directory.- Specified by:
copy
in interfaceIRealFile
- Parameters:
newDir
- The target directory.newName
- The new filenameprogressListener
- Observer to notify of the copy progress.- Returns:
- The new file
- Throws:
IOException
- Thrown if error during IO
-
getChild
Get a child file in this directory. -
renameTo
Rename file.- Specified by:
renameTo
in interfaceIRealFile
- Parameters:
newFilename
- The new filename- Returns:
- True if file renamed
- Throws:
FileNotFoundException
- Thrown if file is not found
-
mkdir
public boolean mkdir()Create this directory. -
getFileDescriptor
Get a file descriptor corresponding to this file.- Parameters:
mode
- The mode- Returns:
- The parcel file descriptor
- Throws:
FileNotFoundException
- Thrown if file is not found
-
toString
Returns a string representation of this object -
clearCache
public void clearCache()Clear the cache
-