public interface UsbFile
extends java.io.Closeable
isDirectory()
. Not all methods make sense for both cases. For
example if representing a file methods like createDirectory(String)
or createFile(String)
do not make sense and will throw an exception.
On the other hand methods like read(long, ByteBuffer)
or
write(long, ByteBuffer)
do not make sense for directories and will
throw an exception!Modifier and Type | Field and Description |
---|---|
static java.lang.String |
separator |
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes and flushes the file.
|
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() |
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.
|
UsbFile |
search(java.lang.String path)
Tries to search a corresponding entry associated with the path parameter.
|
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.
|
static final java.lang.String separator
@Nullable UsbFile search(@NonNull java.lang.String path) throws java.io.IOException
path
- The path to the resource to search.java.io.IOException
boolean isDirectory()
java.lang.String getName()
void setName(java.lang.String newName) throws java.io.IOException
newName
- The new name.java.io.IOException
- If new name is already assigned or writing to the file system
fails.long createdAt()
long lastModified()
long lastAccessed()
UsbFile getParent()
java.lang.String[] list() throws java.io.IOException
java.io.IOException
- If reading failsUsbFile[] listFiles() throws java.io.IOException
java.io.IOException
- If reading failslong getLength()
void setLength(long newLength) throws java.io.IOException
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.
newLength
- The file length in bytes.java.io.IOException
- If requesting the needed space fails.void read(long offset, java.nio.ByteBuffer destination) throws java.io.IOException
offset
- The offset in bytes where reading in the file should be begin.destination
- Buffer the data shall be transferred to.java.io.IOException
- If reading fails.void write(long offset, java.nio.ByteBuffer source) throws java.io.IOException
offset
- The offset in bytes where writing in the file should be begin.source
- Buffer which contains the data which shall be transferred.java.io.IOException
- If writing fails.void flush() throws java.io.IOException
java.io.IOException
- If flushing fails.void close() throws java.io.IOException
close
in interface java.lang.AutoCloseable
close
in interface java.io.Closeable
java.io.IOException
- If closing fails.UsbFile createDirectory(java.lang.String name) throws java.io.IOException
name
- The name of the new directory.java.io.IOException
- If writing to the disk fails or a item with the same name
already exists.UsbFile createFile(java.lang.String name) throws java.io.IOException
name
- The name of the new file.java.io.IOException
- If writing to the disk fails or a item with the same name
already exists.void moveTo(UsbFile destination) throws java.io.IOException
destination
- The directory where this item should be moved.java.io.IOException
- If writing fails, or the operation cannot be done (eg. item
already exists in the destination directory)void delete() throws java.io.IOException
java.io.IOException
- If operation fails due to write errors.boolean isRoot()