Class AndroidFile

java.lang.Object
com.mku.android.file.AndroidFile
All Implemented Interfaces:
IRealFile

public class AndroidFile extends Object implements 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
  • 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 to
      context - Android Context
  • Method Details

    • createDirectory

      public IRealFile createDirectory(String dirName)
      Description copied from interface: IRealFile
      Create the directory with the name provided under this directory.
      Specified by:
      createDirectory in interface IRealFile
      Parameters:
      dirName - Directory name.
      Returns:
      The newly created directory.
    • createFile

      public IRealFile createFile(String filename)
      Description copied from interface: IRealFile
      Create an empty file with the provided name.
      Specified by:
      createFile in interface IRealFile
      Parameters:
      filename - The name for the new file.
      Returns:
      The newly create file.
    • delete

      public boolean delete()
      Delete this file.
      Specified by:
      delete in interface IRealFile
      Returns:
      True if deletion is successful.
    • exists

      public boolean exists()
      True if file exists.
      Specified by:
      exists in interface IRealFile
      Returns:
      True if exists
    • getAbsolutePath

      public String getAbsolutePath()
      Get the absolute path on the physical drive.
      Specified by:
      getAbsolutePath in interface IRealFile
      Returns:
      The absolute path
    • getBaseName

      public String getBaseName()
      Get the base name of this file.
      Specified by:
      getBaseName in interface IRealFile
      Returns:
      The base name
    • getInputStream

      public RandomAccessStream getInputStream() throws FileNotFoundException
      Get a stream for reading.
      Specified by:
      getInputStream in interface IRealFile
      Returns:
      The input stream
      Throws:
      FileNotFoundException - Thrown if file is not found
    • getOutputStream

      public RandomAccessStream getOutputStream() throws FileNotFoundException
      Get a stream for writing.
      Specified by:
      getOutputStream in interface IRealFile
      Returns:
      The output stream
      Throws:
      FileNotFoundException - Thrown if file not found
    • getParent

      public IRealFile getParent()
      Get the parent directory.
      Specified by:
      getParent in interface IRealFile
      Returns:
      The parent directory
    • getPath

      public String getPath()
      Get the path.
      Specified by:
      getPath in interface IRealFile
      Returns:
      The file path
    • isDirectory

      public boolean isDirectory()
      True if it is a directory.
      Specified by:
      isDirectory in interface IRealFile
      Returns:
      True if directory
    • isFile

      public boolean isFile()
      True if it is a file.
      Specified by:
      isFile in interface IRealFile
      Returns:
      True if is file
    • lastModified

      public long lastModified()
      Get the last modified date in milliseconds.
      Specified by:
      lastModified in interface IRealFile
      Returns:
      Last modified date in milliseconds
    • length

      public long length()
      Get the size of the file.
      Specified by:
      length in interface IRealFile
      Returns:
      The size
    • getChildrenCount

      public int getChildrenCount()
      Get the count of files and subdirectories
      Specified by:
      getChildrenCount in interface IRealFile
      Returns:
      The children count
    • listFiles

      public IRealFile[] listFiles()
      List files and directories.
      Specified by:
      listFiles in interface IRealFile
      Returns:
      The files and subdirectories
    • move

      public IRealFile move(IRealFile newDir) throws IOException
      Move this file to another directory.
      Specified by:
      move in interface IRealFile
      Parameters:
      newDir - The target directory.
      Returns:
      The moved file
      Throws:
      IOException - Thrown if error during IO
    • move

      public IRealFile move(IRealFile newDir, String newName) throws IOException
      Move this file to another directory.
      Specified by:
      move in interface IRealFile
      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 IOException
      Move this file to another directory.
      Specified by:
      move in interface IRealFile
      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

      public IRealFile copy(IRealFile newDir) throws IOException
      Copy this file to another directory.
      Specified by:
      copy in interface IRealFile
      Parameters:
      newDir - The target directory.
      Returns:
      The new file
      Throws:
      IOException - Thrown if error during IO
    • copy

      public IRealFile copy(IRealFile newDir, String newName) throws IOException
      Copy this file to another directory.
      Specified by:
      copy in interface IRealFile
      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 IOException
      Copy this file to another directory.
      Specified by:
      copy in interface IRealFile
      Parameters:
      newDir - The target directory.
      newName - The new filename
      progressListener - Observer to notify of the copy progress.
      Returns:
      The new file
      Throws:
      IOException - Thrown if error during IO
    • getChild

      public IRealFile getChild(String filename)
      Get a child file in this directory.
      Specified by:
      getChild in interface IRealFile
      Parameters:
      filename - The name of the file or directory to match.
      Returns:
      The child file
    • renameTo

      public boolean renameTo(String newFilename) throws FileNotFoundException
      Rename file.
      Specified by:
      renameTo in interface IRealFile
      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.
      Specified by:
      mkdir in interface IRealFile
      Returns:
      True if directory created
    • getFileDescriptor

      public ParcelFileDescriptor getFileDescriptor(String mode) throws FileNotFoundException
      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

      public String toString()
      Returns a string representation of this object
      Overrides:
      toString in class Object
    • clearCache

      public void clearCache()
      Clear the cache