Class FatFile

  • All Implemented Interfaces:
    UsbFile, java.io.Closeable, java.lang.AutoCloseable

    public class FatFile
    extends AbstractUsbFile
    • Field Summary

    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()
      Closes and flushes the file.
      static FatFile create​(com.github.mjdev.libaums.fs.fat32.FatLfnDirectoryEntry entry, BlockDeviceDriver blockDevice, FAT fat, com.github.mjdev.libaums.fs.fat32.Fat32BootSector bootSector, FatDirectory parent)
      Creates a new file with the given information.
      long createdAt()
      Returns the time this directory or file was created.
      UsbFile createDirectory​(java.lang.String name)
      This methods creates a new directory with the given name and returns it.
      UsbFile createFile​(java.lang.String name)
      This methods creates a new file with the given name and returns it.
      void delete()
      Deletes this file or directory from the parent directory.
      void flush()
      Forces a write.
      long getLength()
      Returns the file length or throws an exception if called on a directory.
      java.lang.String getName()
      Actual file or directory name or '/' for root directory.
      UsbFile getParent()
      Returns the parent directory for the file or directory or null if this is the root directory.
      boolean isDirectory()  
      boolean isRoot()  
      long lastAccessed()
      Returns the time this directory or file was last accessed.
      long lastModified()
      Returns the time this directory or file was last modified.
      java.lang.String[] list()
      Lists all files in the directory.
      UsbFile[] listFiles()
      Lists all files in the directory.
      void moveTo​(UsbFile destination)
      This methods moves THIS item to the destination directory.
      void read​(long offset, java.nio.ByteBuffer destination)
      Reads from a file or throws an exception if called on a directory.
      void setLength​(long newLength)
      Sets the new file length.
      void setName​(java.lang.String newName)
      Set a new name for this file or directory.
      void write​(long offset, java.nio.ByteBuffer source)
      Writes to a file or throws an exception if called on a directory.
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Method Detail

      • create

        public static FatFile create​(com.github.mjdev.libaums.fs.fat32.FatLfnDirectoryEntry entry,
                                     BlockDeviceDriver blockDevice,
                                     FAT fat,
                                     com.github.mjdev.libaums.fs.fat32.Fat32BootSector bootSector,
                                     FatDirectory parent)
                              throws java.io.IOException
        Creates a new file with the given information.
        Parameters:
        entry - The corresponding entry in a FAT directory.
        blockDevice - The device where the file system is located.
        fat - The FAT used to follow cluster chains.
        bootSector - The boot sector of the file system.
        parent - The parent directory of the newly created file.
        Returns:
        The newly constructed file.
        Throws:
        java.io.IOException - If reading from device fails.
      • isDirectory

        public boolean isDirectory()
        Returns:
        True if representing a directory.
      • getName

        public java.lang.String getName()
        Description copied from interface: UsbFile
        Actual file or directory name or '/' for root directory.
        Returns:
        The name of the file or directory.
      • setName

        public void setName​(java.lang.String newName)
                     throws java.io.IOException
        Description copied from interface: UsbFile
        Set a new name for this file or directory.
        Parameters:
        newName - The new name.
        Throws:
        java.io.IOException - If new name is already assigned or writing to the file system fails.
      • createdAt

        public long createdAt()
        Description copied from interface: UsbFile
        Returns the time this directory or file was created.
        Returns:
        Time in milliseconds since January 1 00:00:00, 1970 UTC
      • lastModified

        public long lastModified()
        Description copied from interface: UsbFile
        Returns the time this directory or file was last modified.
        Returns:
        Time in milliseconds since January 1 00:00:00, 1970 UTC
      • lastAccessed

        public long lastAccessed()
        Description copied from interface: UsbFile
        Returns the time this directory or file was last accessed.
        Returns:
        Time in milliseconds since January 1 00:00:00, 1970 UTC
      • getParent

        public UsbFile getParent()
        Description copied from interface: UsbFile
        Returns the parent directory for the file or directory or null if this is the root directory.
        Returns:
        The parent directory or null.
      • list

        public java.lang.String[] list()
        Description copied from interface: UsbFile
        Lists all files in the directory. Throws an exception if called on a file.
        Returns:
        String array containing all names in the directory.
      • listFiles

        public UsbFile[] listFiles()
                            throws java.io.IOException
        Description copied from interface: UsbFile
        Lists all files in the directory. Throws an exception if called on a file.
        Returns:
        UsbFile array containing all files or directories in the directory.
        Throws:
        java.io.IOException - If reading fails
      • getLength

        public long getLength()
        Description copied from interface: UsbFile
        Returns the file length or throws an exception if called on a directory.
        Returns:
        File length in bytes.
      • setLength

        public void setLength​(long newLength)
                       throws java.io.IOException
        Description copied from interface: UsbFile
        Sets the new file length. This can sometimes be more efficient if all needed place for a file is allocated on the disk at once and before writing to it.

        If the space is not allocated before writing the space must be exceeded every time a new write occurs. This can sometimes be less efficient.

        Parameters:
        newLength - The file length in bytes.
        Throws:
        java.io.IOException - If requesting the needed space fails.
      • read

        public void read​(long offset,
                         java.nio.ByteBuffer destination)
                  throws java.io.IOException
        Description copied from interface: UsbFile
        Reads from a file or throws an exception if called on a directory.
        Parameters:
        offset - The offset in bytes where reading in the file should be begin.
        destination - Buffer the data shall be transferred to.
        Throws:
        java.io.IOException - If reading fails.
      • write

        public void write​(long offset,
                          java.nio.ByteBuffer source)
                   throws java.io.IOException
        Description copied from interface: UsbFile
        Writes to a file or throws an exception if called on a directory.
        Parameters:
        offset - The offset in bytes where writing in the file should be begin.
        source - Buffer which contains the data which shall be transferred.
        Throws:
        java.io.IOException - If writing fails.
      • flush

        public void flush()
                   throws java.io.IOException
        Description copied from interface: UsbFile
        Forces a write. Every change to the file is then committed to the disk. Throws an exception if called on directories.
        Throws:
        java.io.IOException - If flushing fails.
      • close

        public void close()
                   throws java.io.IOException
        Description copied from interface: UsbFile
        Closes and flushes the file. It is essential to close a file after making changes to it! Throws an exception if called on directories.
        Throws:
        java.io.IOException - If closing fails.
      • createDirectory

        public UsbFile createDirectory​(java.lang.String name)
                                throws java.io.IOException
        Description copied from interface: UsbFile
        This methods creates a new directory with the given name and returns it.
        Parameters:
        name - The name of the new directory.
        Returns:
        The newly created directory.
        Throws:
        java.io.IOException - If writing to the disk fails or a item with the same name already exists.
      • createFile

        public UsbFile createFile​(java.lang.String name)
                           throws java.io.IOException
        Description copied from interface: UsbFile
        This methods creates a new file with the given name and returns it.
        Parameters:
        name - The name of the new file.
        Returns:
        The newly created file.
        Throws:
        java.io.IOException - If writing to the disk fails or a item with the same name already exists.
      • moveTo

        public void moveTo​(UsbFile destination)
                    throws java.io.IOException
        Description copied from interface: UsbFile
        This methods moves THIS item to the destination directory. Make sure that the destination is a directory, otherwise an exception will be thrown. Make also sure that both items are on the same logical device (disk, partition, file system). Moving between different file systems is currently not supported. If you want to do this, you have to manually copy the content and delete the old item.
        Parameters:
        destination - The directory where this item should be moved.
        Throws:
        java.io.IOException - If writing fails, or the operation cannot be done (eg. item already exists in the destination directory)
      • delete

        public void delete()
                    throws java.io.IOException
        Description copied from interface: UsbFile
        Deletes this file or directory from the parent directory.
        Throws:
        java.io.IOException - If operation fails due to write errors.
      • isRoot

        public boolean isRoot()
        Returns:
        True if the current directory is the root directory, false if not or a file.