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 Details

    • autoRename

      static final Function<IRealFile,String> 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

      RandomAccessStream getInputStream() throws FileNotFoundException
      Get a stream for reading the file.
      Returns:
      The input stream
      Throws:
      FileNotFoundException - Thrown if file not found
    • getOutputStream

      RandomAccessStream getOutputStream() throws FileNotFoundException
      Get a stream for writing to the file.
      Returns:
      The output stream
      Throws:
      FileNotFoundException - Thrown if file not found
    • renameTo

      boolean renameTo(String newFilename) throws FileNotFoundException
      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 use getAbsolutePath().
      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

      IRealFile createDirectory(String dirName)
      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

      IRealFile createFile(String filename) throws IOException
      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

      IRealFile move(IRealFile newDir) throws IOException
      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

      IRealFile move(IRealFile newDir, String newName) throws IOException
      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 IOException
      Move 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

      IRealFile copy(IRealFile newDir) throws IOException
      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

      IRealFile copy(IRealFile newDir, String newName) throws IOException
      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 IOException
      Copy 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

      IRealFile getChild(String filename)
      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 IOException
      Copy contents of a file to another file.
      Parameters:
      src - The source directory
      dest - The target directory
      delete - True to delete the source files when complete
      progressListener - The progress listener
      Returns:
      True if contents were copied
      Throws:
      IOException - Thrown if there is an IO error.
    • copyRecursively

      default void copyRecursively(IRealFile dest) throws IOException
      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,Long> progressListener, Function<IRealFile,String> autoRename, boolean autoRenameFolders, BiConsumer<IRealFile,Exception> onFailed) throws IOException
      Copy a directory recursively
      Parameters:
      destDir - The destination directory
      progressListener - The progress listener
      autoRename - The autorename function
      autoRenameFolders - Apply autorename to folders also (default is true)
      onFailed - Callback if copy failed
      Throws:
      IOException - Thrown if there is an IO error.
    • moveRecursively

      default void moveRecursively(IRealFile dest) throws IOException
      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,Long> progressListener, Function<IRealFile,String> autoRename, boolean autoRenameFolders, BiConsumer<IRealFile,Exception> onFailed) throws IOException
      Move a directory recursively
      Parameters:
      destDir - The target directory
      progressListener - The progress listener
      autoRename - The autorename function
      autoRenameFolders - 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 listener
      onFailed - Callback when delete failed
    • autoRename

      static String autoRename(String filename)
      Get an auto generated copy of a filename
      Parameters:
      filename - The file name
      Returns:
      The new file name