Class FatDirectory
- java.lang.Object
-
- com.github.mjdev.libaums.fs.AbstractUsbFile
-
- com.github.mjdev.libaums.fs.fat32.FatDirectory
-
- All Implemented Interfaces:
UsbFile,java.io.Closeable,java.lang.AutoCloseable
public class FatDirectory extends AbstractUsbFile
This class represents a directory in the FAT32 file system. It can hold other directories and files.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Closes and flushes the file.longcreatedAt()Returns the time this directory or file was created.FatDirectorycreateDirectory(java.lang.String name)This methods creates a new directory with the given name and returns it.FatFilecreateFile(java.lang.String name)This methods creates a new file with the given name and returns it.voiddelete()Deletes this file or directory from the parent directory.voidflush()Forces a write.longgetLength()Returns the file length or throws an exception if called on a directory.java.lang.StringgetName()Actual file or directory name or '/' for root directory.UsbFilegetParent()Returns the parent directory for the file or directory or null if this is the root directory.booleanisDirectory()booleanisRoot()longlastAccessed()Returns the time this directory or file was last accessed.longlastModified()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.voidmoveTo(UsbFile destination)This methods moves THIS item to the destination directory.voidread(long offset, java.nio.ByteBuffer destination)Reads from a file or throws an exception if called on a directory.voidsetLength(long newLength)Sets the new file length.voidsetName(java.lang.String newName)Set a new name for this file or directory.voidwrite(long offset, java.nio.ByteBuffer source)Writes to a file or throws an exception if called on a directory.-
Methods inherited from class com.github.mjdev.libaums.fs.AbstractUsbFile
equals, getAbsolutePath, hashCode, search, toString
-
-
-
-
Method Detail
-
isRoot
public boolean isRoot()
- Returns:
- True if this directory is the root directory.
-
createFile
public FatFile createFile(java.lang.String name) throws java.io.IOException
Description copied from interface:UsbFileThis 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.
-
createDirectory
public FatDirectory createDirectory(java.lang.String name) throws java.io.IOException
Description copied from interface:UsbFileThis 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.
-
setLength
public void setLength(long newLength)
Description copied from interface:UsbFileSets 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.
-
getLength
public long getLength()
Description copied from interface:UsbFileReturns the file length or throws an exception if called on a directory.- Returns:
- File length in bytes.
-
isDirectory
public boolean isDirectory()
- Returns:
- True if representing a directory.
-
getName
public java.lang.String getName()
Description copied from interface:UsbFileActual 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.IOExceptionDescription copied from interface:UsbFileSet 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:UsbFileReturns 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:UsbFileReturns 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:UsbFileReturns 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:UsbFileReturns 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() throws java.io.IOExceptionDescription copied from interface:UsbFileLists all files in the directory. Throws an exception if called on a file.- Returns:
- String array containing all names in the directory.
- Throws:
java.io.IOException- If reading fails
-
listFiles
public UsbFile[] listFiles() throws java.io.IOException
Description copied from interface:UsbFileLists 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
-
read
public void read(long offset, java.nio.ByteBuffer destination) throws java.io.IOExceptionDescription copied from interface:UsbFileReads 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.IOExceptionDescription copied from interface:UsbFileWrites 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.IOExceptionDescription copied from interface:UsbFileForces 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.IOExceptionDescription copied from interface:UsbFileCloses 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.
-
moveTo
public void moveTo(UsbFile destination) throws java.io.IOException
Description copied from interface:UsbFileThis 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.IOExceptionDescription copied from interface:UsbFileDeletes this file or directory from the parent directory.- Throws:
java.io.IOException- If operation fails due to write errors.
-
-