-
- All Implemented Interfaces:
-
com.github.mjdev.libaums.fs.UsbFile,java.io.Closeable,java.lang.AutoCloseable
public final class FatFile extends AbstractUsbFile
Constructs a new file with the given information.
-
-
Field Summary
Fields Modifier and Type Field Description private final BooleanisDirectoryprivate Stringnameprivate Longlengthprivate final BooleanisRootprivate FatDirectoryparentprivate final StringabsolutePath
-
Method Summary
Modifier and Type Method Description BooleangetIsDirectory()StringgetName()Set a new name for this file or directory. UnitsetName(String name)Set a new name for this file or directory. LonggetLength()Sets the new file length. UnitsetLength(Long length)Sets the new file length. BooleangetIsRoot()FatDirectorygetParent()UnitsetParent(FatDirectory parent)StringgetAbsolutePath()Absolute path of a file or directory. LongcreatedAt()Returns the time this directory or file was created. LonglastModified()Returns the time this directory or file was last modified. LonglastAccessed()Returns the time this directory or file was last accessed. Array<String>list()Lists all files in the directory. Array<UsbFile>listFiles()Lists all files in the directory. Unitread(Long offset, ByteBuffer destination)Reads from a file or throws an exception if called on a directory. Unitwrite(Long offset, ByteBuffer source)Writes to a file or throws an exception if called on a directory. Unitflush()Forces a write. Unitclose()Closes and flushes the file. UsbFilecreateDirectory(String name)This methods creates a new directory with the given name and returns it. UsbFilecreateFile(String name)This methods creates a new file with the given name and returns it. UnitmoveTo(UsbFile destination)This methods moves THIS item to the destination directory. Unitdelete()Deletes this file or directory from the parent directory. -
-
Method Detail
-
getIsDirectory
Boolean getIsDirectory()
-
setName
Unit setName(String name)
Set a new name for this file or directory.
- Parameters:
name- The new name.
-
getLength
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
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.
-
getParent
FatDirectory getParent()
-
setParent
Unit setParent(FatDirectory parent)
- Parameters:
parent- The parent directory of the newly constructed file.
-
getAbsolutePath
String getAbsolutePath()
Absolute path of a file or directory.
-
lastModified
Long lastModified()
Returns the time this directory or file was last modified.
-
lastAccessed
Long lastAccessed()
Returns the time this directory or file was last accessed.
-
list
Array<String> list()
Lists all files in the directory. Throws an exception if called on a file.
-
listFiles
Array<UsbFile> listFiles()
Lists all files in the directory. Throws an exception if called on a file.
-
read
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
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
Unit flush()
Forces a write. Every change to the file is then committed to the disk. Throws an exception if called on directories.
-
close
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
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
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
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.
-
-
-
-