Package 

Interface UsbFile

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

    
    public interface UsbFile
     implements Closeable
                        

    This class represents either an file or an directory. This can be determined by .isDirectory. Not all methods make sense for both cases. For example if representing a file methods like .createDirectory or .createFile do not make sense and will throw an exception. On the other hand methods like .read or .write do not make sense for directories and will throw an exception!

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      public class UsbFile.Companion
    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Constructor Summary

      Constructors 
      Constructor Description
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      abstract UsbFile search(String path) Tries to search a corresponding entry associated with the path parameter.
      abstract Long createdAt() Returns the time this directory or file was created.
      abstract Long lastModified() Returns the time this directory or file was last modified.
      abstract Long lastAccessed() Returns the time this directory or file was last accessed.
      abstract Array<String> list() Lists all files in the directory.
      abstract Array<UsbFile> listFiles() Lists all files in the directory.
      abstract Unit read(Long offset, ByteBuffer destination) Reads from a file or throws an exception if called on a directory.
      abstract Unit write(Long offset, ByteBuffer source) Writes to a file or throws an exception if called on a directory.
      abstract Unit flush() Forces a write.
      abstract Unit close() Closes and flushes the file.
      abstract UsbFile createDirectory(String name) This methods creates a new directory with the given name and returns it.
      abstract UsbFile createFile(String name) This methods creates a new file with the given name and returns it.
      abstract Unit moveTo(UsbFile destination) This methods moves THIS item to the destination directory.
      abstract Unit delete() Deletes this file or directory from the parent directory.
      abstract Boolean getIsDirectory()
      abstract String getName() Set a new name for this file or directory.
      abstract Unit setName(String name) Set a new name for this file or directory.
      abstract String getAbsolutePath() Absolute path of a file or directory.
      abstract UsbFile getParent() Returns the parent directory for the file or directory or null if this is the root directory.
      abstract Long getLength() Sets the new file length.
      abstract Unit setLength(Long length) Sets the new file length.
      abstract Boolean getIsRoot()
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

    • Method Detail

      • search

         abstract UsbFile search(String path)

        Tries to search a corresponding entry associated with the path parameter. Path separator is '/'. Parameter path must not start with an '/' (except if querying from root directory). Path is treated relative to current UsbFile.

        Parameters:
        path - The path to the resource to search.
      • createdAt

         abstract Long createdAt()

        Returns the time this directory or file was created.

      • lastModified

         abstract Long lastModified()

        Returns the time this directory or file was last modified.

      • lastAccessed

         abstract Long lastAccessed()

        Returns the time this directory or file was last accessed.

      • list

         abstract Array<String> list()

        Lists all files in the directory. Throws an exception if called on a file.

      • listFiles

         abstract Array<UsbFile> listFiles()

        Lists all files in the directory. Throws an exception if called on a file.

      • read

         abstract Unit read(Long offset, ByteBuffer destination)

        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.
      • write

         abstract Unit write(Long offset, ByteBuffer source)

        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.
      • flush

         abstract Unit flush()

        Forces a write. Every change to the file is then committed to the disk. Throws an exception if called on directories.

      • close

         abstract Unit close()

        Closes and flushes the file. It is essential to close a file after making changes to it! Throws an exception if called on directories.

      • createDirectory

         abstract UsbFile createDirectory(String name)

        This methods creates a new directory with the given name and returns it.

        Parameters:
        name - The name of the new directory.
      • createFile

         abstract UsbFile createFile(String name)

        This methods creates a new file with the given name and returns it.

        Parameters:
        name - The name of the new file.
      • moveTo

         abstract Unit moveTo(UsbFile destination)

        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.
      • delete

         abstract Unit delete()

        Deletes this file or directory from the parent directory.

      • getName

         abstract String getName()

        Set a new name for this file or directory.

      • setName

         abstract Unit setName(String name)

        Set a new name for this file or directory.

        Parameters:
        name - The new name.
      • getParent

         abstract UsbFile getParent()

        Returns the parent directory for the file or directory or null if this is the root directory.

      • getLength

         abstract Long getLength()

        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.

      • setLength

         abstract Unit setLength(Long length)

        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:
        length - The file length in bytes.