Package com.mku.file
Interface IRealFile
- All Known Implementing Classes:
AndroidFile
,JavaFile
public interface IRealFile
Interface that represents a real file. This class is used internally by the virtual disk to
import, store, and export the encrypted files.
Extend this to provide an interface to any file system, platform, or API ie: on disk, memory, network, or cloud.
-
Field Summary
Modifier and TypeFieldDescriptionGet an auto generated copy of the name for a file. -
Method Summary
Modifier and TypeMethodDescriptionstatic String
autoRename
(String filename) Get an auto generated copy of a filenameCopy this file to another directory.Copy this file to another directory.Copy this file to another directory.static boolean
copyFileContents
(IRealFile src, IRealFile dest, boolean delete, BiConsumer<Long, Long> progressListener) Copy contents of a file to another file.default void
copyRecursively
(IRealFile dest) Copy a directory recursivelydefault void
copyRecursively
(IRealFile destDir, TriConsumer<IRealFile, Long, Long> progressListener, Function<IRealFile, String> autoRename, boolean autoRenameFolders, BiConsumer<IRealFile, Exception> onFailed) Copy a directory recursivelycreateDirectory
(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.default void
deleteRecursively
(TriConsumer<IRealFile, Long, Long> progressListener, BiConsumer<IRealFile, Exception> onFailed) Delete a directory recursivelyboolean
exists()
True if this file exists.Get the absolute path of the file on disk.Get the basename of the file.Get the file/directory matching the name provided under this directory.int
Get the count of files and subdirectoriesGet a stream for reading the file.Get a stream for writing to the file.Get the parent directory of this file/directory.getPath()
Get the original filepath of this file.boolean
True if this is a directory.boolean
isFile()
True if this is a file.long
Get the last modified date of the file.long
length()
Get the length for the file.Get all files and directories under this directory.boolean
mkdir()
Create a directory with the current filepath.Move this file to another directory.Move this file to another directory.Move this file to another directory.default void
moveRecursively
(IRealFile dest) Move a directory recursivelydefault void
moveRecursively
(IRealFile destDir, TriConsumer<IRealFile, Long, Long> progressListener, Function<IRealFile, String> autoRename, boolean autoRenameFolders, BiConsumer<IRealFile, Exception> onFailed) Move a directory recursivelyboolean
Rename file.
-
Field Details
-
autoRename
Get an auto generated copy of the name for a file.
-
-
Method Details
-
exists
boolean exists()True if this file exists.- Returns:
- True if file exists
-
delete
boolean delete()Delete this file.- Returns:
- True if file deleted.
-
getInputStream
Get a stream for reading the file.- Returns:
- The input stream
- Throws:
FileNotFoundException
- Thrown if file not found
-
getOutputStream
Get a stream for writing to the file.- Returns:
- The output stream
- Throws:
FileNotFoundException
- Thrown if file not found
-
renameTo
Rename file.- Parameters:
newFilename
- The new filename- Returns:
- True if success.
- Throws:
FileNotFoundException
- Thrown if file not found
-
length
long length()Get the length for the file.- Returns:
- The length.
-
getChildrenCount
int getChildrenCount()Get the count of files and subdirectories- Returns:
- The children count
-
lastModified
long lastModified()Get the last modified date of the file.- Returns:
- The last date modified in milliseconds
-
getAbsolutePath
String getAbsolutePath()Get the absolute path of the file on disk.- Returns:
- The absolute path
-
getPath
String getPath()Get the original filepath of this file. This might symlinks or merged folders. To get the absolute path usegetAbsolutePath()
.- Returns:
- The file path
-
isFile
boolean isFile()True if this is a file.- Returns:
- True if this is a file
-
isDirectory
boolean isDirectory()True if this is a directory.- Returns:
- True if this is a directory.
-
listFiles
IRealFile[] listFiles()Get all files and directories under this directory.- Returns:
- The files
-
getBaseName
String getBaseName()Get the basename of the file.- Returns:
- The base name
-
createDirectory
Create the directory with the name provided under this directory.- Parameters:
dirName
- Directory name.- Returns:
- The newly created directory.
-
getParent
IRealFile getParent()Get the parent directory of this file/directory.- Returns:
- The parent directory.
-
createFile
Create an empty file with the provided name.- Parameters:
filename
- The name for the new file.- Returns:
- The newly create file.
- Throws:
IOException
- Thrown if there is an IO error.
-
move
Move this file to another directory.- Parameters:
newDir
- The target directory.- Returns:
- The file after the move. Use this instance for any subsequent file operations.
- Throws:
IOException
- Thrown if there is an IO error.
-
move
Move this file to another directory.- Parameters:
newDir
- The target directory.newName
- The new filename.- Returns:
- The file after the move. Use this instance for any subsequent file operations.
- Throws:
IOException
- Thrown if there is an IO error.
-
move
IRealFile move(IRealFile newDir, String newName, BiConsumer<Long, Long> progressListener) throws IOExceptionMove this file to another directory.- Parameters:
newDir
- The target directory.newName
- The new filename.progressListener
- Observer to notify of the move progress.- Returns:
- The file after the move. Use this instance for any subsequent file operations.
- Throws:
IOException
- Thrown if there is an IO error.
-
copy
Copy this file to another directory.- Parameters:
newDir
- The target directory.- Returns:
- The file after the copy. Use this instance for any subsequent file operations.
- Throws:
IOException
- Thrown if there is an IO error.
-
copy
Copy this file to another directory.- Parameters:
newDir
- The target directory.newName
- The new filename.- Returns:
- The file after the copy. Use this instance for any subsequent file operations.
- Throws:
IOException
- Thrown if there is an IO error.
-
copy
IRealFile copy(IRealFile newDir, String newName, BiConsumer<Long, Long> progressListener) throws IOExceptionCopy this file to another directory.- Parameters:
newDir
- The target directory.newName
- The new filename.progressListener
- Observer to notify of the copy progress.- Returns:
- The file after the copy. Use this instance for any subsequent file operations.
- Throws:
IOException
- Thrown if there is an IO error.
-
getChild
Get the file/directory matching the name provided under this directory.- Parameters:
filename
- The name of the file or directory to match.- Returns:
- The file that was matched.
-
mkdir
boolean mkdir()Create a directory with the current filepath.- Returns:
- True if directory was created
-
copyFileContents
static boolean copyFileContents(IRealFile src, IRealFile dest, boolean delete, BiConsumer<Long, Long> progressListener) throws IOExceptionCopy contents of a file to another file.- Parameters:
src
- The source directorydest
- The target directorydelete
- True to delete the source files when completeprogressListener
- The progress listener- Returns:
- True if contents were copied
- Throws:
IOException
- Thrown if there is an IO error.
-
copyRecursively
Copy a directory recursively- Parameters:
dest
- Destination directory- Throws:
IOException
- Thrown if there is an IO error.
-
copyRecursively
default void copyRecursively(IRealFile destDir, TriConsumer<IRealFile, Long, throws IOExceptionLong> progressListener, Function<IRealFile, String> autoRename, boolean autoRenameFolders, BiConsumer<IRealFile, Exception> onFailed) Copy a directory recursively- Parameters:
destDir
- The destination directoryprogressListener
- The progress listenerautoRename
- The autorename functionautoRenameFolders
- Apply autorename to folders also (default is true)onFailed
- Callback if copy failed- Throws:
IOException
- Thrown if there is an IO error.
-
moveRecursively
Move a directory recursively- Parameters:
dest
- The target directory- Throws:
IOException
- Thrown if there is an IO error.
-
moveRecursively
default void moveRecursively(IRealFile destDir, TriConsumer<IRealFile, Long, throws IOExceptionLong> progressListener, Function<IRealFile, String> autoRename, boolean autoRenameFolders, BiConsumer<IRealFile, Exception> onFailed) Move a directory recursively- Parameters:
destDir
- The target directoryprogressListener
- The progress listenerautoRename
- The autorename functionautoRenameFolders
- Apply autorename to folders also (default is true)onFailed
- Callback when move failed- Throws:
IOException
- Thrown if there is an IO error.
-
deleteRecursively
default void deleteRecursively(TriConsumer<IRealFile, Long, Long> progressListener, BiConsumer<IRealFile, Exception> onFailed) Delete a directory recursively- Parameters:
progressListener
- The progress listeneronFailed
- Callback when delete failed
-
autoRename
Get an auto generated copy of a filename- Parameters:
filename
- The file name- Returns:
- The new file name
-