Class AndroidFile

  • All Implemented Interfaces:
    IFile

    public class AndroidFile
    extends java.lang.Object
    implements IFile
    Implementation of the IFile 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 AesFile wrapper transparently
    • Constructor Detail

      • 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 Detail

      • createDirectory

        public IFile createDirectory​(java.lang.String dirName)
        Create a directory under this directory.
        Specified by:
        createDirectory in interface IFile
        Parameters:
        dirName - The directory name.
        Returns:
        The new directory.
      • createFile

        public IFile createFile​(java.lang.String filename)
        Create an empty file under this directory.
        Specified by:
        createFile in interface IFile
        Parameters:
        filename - The file name.
        Returns:
        The new file.
      • delete

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

        public boolean exists()
        Check if file exists.
        Specified by:
        exists in interface IFile
        Returns:
        True if exists
      • getDisplayPath

        public java.lang.String getDisplayPath()
        Get the display path on the physical drive.
        Specified by:
        getDisplayPath in interface IFile
        Returns:
        The display path
      • getName

        public java.lang.String getName()
        Get the base name of this file.
        Specified by:
        getName in interface IFile
        Returns:
        The base name
      • getInputStream

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

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

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

        public java.lang.String getPath()
        Get the path on the physical disk.
        Specified by:
        getPath in interface IFile
        Returns:
        The file path
      • isDirectory

        public boolean isDirectory()
        Check if this is a directory.
        Specified by:
        isDirectory in interface IFile
        Returns:
        True if directory
      • isFile

        public boolean isFile()
        Check if this is a file.
        Specified by:
        isFile in interface IFile
        Returns:
        True if is file
      • getLastDateModified

        public long getLastDateModified()
        Get the last modified date in milliseconds.
        Specified by:
        getLastDateModified in interface IFile
        Returns:
        Last modified date in milliseconds.
      • getLength

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

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

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

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

        public IFile move​(IFile newDir,
                          IFile.MoveOptions options)
                   throws java.io.IOException
        Move this file to another directory.
        Specified by:
        move in interface IFile
        Parameters:
        newDir - The target directory.
        options - The options.
        Returns:
        The moved file
        Throws:
        java.io.IOException - Thrown if error during IO
      • copy

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

        public IFile copy​(IFile newDir,
                          IFile.CopyOptions options)
                   throws java.io.IOException
        Copy this file to another directory with a new filename with a progress.
        Specified by:
        copy in interface IFile
        Parameters:
        newDir - The target directory.
        options - The options
        Returns:
        The new file
        Throws:
        java.io.IOException - Thrown if error during IO
      • getChild

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

        public boolean renameTo​(java.lang.String newFilename)
                         throws java.io.FileNotFoundException
        Rename this file.
        Specified by:
        renameTo in interface IFile
        Parameters:
        newFilename - The new filename
        Returns:
        True if file renamed
        Throws:
        java.io.FileNotFoundException - Thrown if file is not found
      • mkdir

        public boolean mkdir()
        Create this directory.
        Specified by:
        mkdir in interface IFile
        Returns:
        True if directory created
      • reset

        public void reset()
        Clear cache properties.
        Specified by:
        reset in interface IFile
      • getFileDescriptor

        public ParcelFileDescriptor getFileDescriptor​(java.lang.String mode)
                                               throws java.io.FileNotFoundException
        Get a file descriptor corresponding to this file.
        Parameters:
        mode - The mode
        Returns:
        The parcel file descriptor
        Throws:
        java.io.FileNotFoundException - Thrown if file is not found
      • toString

        public java.lang.String toString()
        Returns a string representation of this object
        Overrides:
        toString in class java.lang.Object