-
- 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 classUsbFile.Companion
-
Method Summary
Modifier and Type Method Description abstract UsbFilesearch(String path)Tries to search a corresponding entry associated with the path parameter. abstract LongcreatedAt()Returns the time this directory or file was created. abstract LonglastModified()Returns the time this directory or file was last modified. abstract LonglastAccessed()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 Unitread(Long offset, ByteBuffer destination)Reads from a file or throws an exception if called on a directory. abstract Unitwrite(Long offset, ByteBuffer source)Writes to a file or throws an exception if called on a directory. abstract Unitflush()Forces a write. abstract Unitclose()Closes and flushes the file. abstract UsbFilecreateDirectory(String name)This methods creates a new directory with the given name and returns it. abstract UsbFilecreateFile(String name)This methods creates a new file with the given name and returns it. abstract UnitmoveTo(UsbFile destination)This methods moves THIS item to the destination directory. abstract Unitdelete()Deletes this file or directory from the parent directory. abstract BooleangetIsDirectory()abstract StringgetName()Set a new name for this file or directory. abstract UnitsetName(String name)Set a new name for this file or directory. abstract StringgetAbsolutePath()Absolute path of a file or directory. abstract UsbFilegetParent()Returns the parent directory for the file or directory or null if this is the root directory. abstract LonggetLength()Sets the new file length. abstract UnitsetLength(Long length)Sets the new file length. abstract BooleangetIsRoot()-
-
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.
-
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.
-
getIsDirectory
abstract Boolean getIsDirectory()
-
setName
abstract Unit setName(String name)
Set a new name for this file or directory.
- Parameters:
name- The new name.
-
getAbsolutePath
abstract String getAbsolutePath()
Absolute path of a file or directory.
-
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.
-
-
-
-