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
ConstructorsConstructorDescriptionAndroidFile(DocumentFile documentFile, Context context) Construct an AndroidFile wrapper from an Android DocumentFile. -
Method Summary
Modifier and TypeMethodDescriptionvoidClear 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.booleandelete()Delete this file.booleanexists()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.intGet the count of files and subdirectoriesParcelFileDescriptorgetFileDescriptor(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.booleanTrue if it is a directory.booleanisFile()True if it is a file.longGet the last modified date in milliseconds.longlength()Get the size of the file.List files and directories.booleanmkdir()Create this directory.Move this file to another directory.Move this file to another directory.Move this file to another directory.booleanRename file.toString()Returns a string representation of this objectMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods 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:IRealFileCreate the directory with the name provided under this directory.- Specified by:
createDirectoryin interfaceIRealFile- Parameters:
dirName- Directory name.- Returns:
- The newly created directory.
-
createFile
Description copied from interface:IRealFileCreate an empty file with the provided name.- Specified by:
createFilein 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:
getAbsolutePathin interfaceIRealFile- Returns:
- The absolute path
-
getBaseName
Get the base name of this file.- Specified by:
getBaseNamein interfaceIRealFile- Returns:
- The base name
-
getInputStream
Get a stream for reading.- Specified by:
getInputStreamin interfaceIRealFile- Returns:
- The input stream
- Throws:
FileNotFoundException- Thrown if file is not found
-
getOutputStream
Get a stream for writing.- Specified by:
getOutputStreamin 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:
isDirectoryin 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:
lastModifiedin 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:
getChildrenCountin interfaceIRealFile- Returns:
- The children count
-
listFiles
List files and directories. -
move
Move this file to another directory.- Specified by:
movein 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:
movein 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:
movein 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:
copyin 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:
copyin 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:
copyin 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:
renameToin 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
-