public interface FileSystem extends Persistable
FileSystem
for factory methods.
Note that all paths passed here are assumed to be absolute in the underlying
file system implementation, meaning they do not contain any "." or "..", and
are relative to the root of the file system. When wrapping a file system in
a node with the provided factory functions this is automatically ensured. If
you call any of the functions of a file system directly it is your
responsibility to ensure the path has been cleaned up.Modifier and Type | Method and Description |
---|---|
void |
close()
Called when the file system is destroyed.
|
boolean |
delete(java.lang.String path)
Deletes a file or folder.
|
boolean |
exists(java.lang.String path)
Tests if a file or directory exists at the specified path.
|
Handle |
getHandle(int handle)
Gets a wrapper for a file previously opened using
open(java.lang.String, li.cil.oc.api.fs.Mode) . |
boolean |
isDirectory(java.lang.String path)
Tests whether the object at the specified path is a directory.
|
boolean |
isReadOnly()
Whether this file system is read-only.
|
long |
lastModified(java.lang.String path)
Gets the timestamp of the last time the file at the specified path was
written to.
|
java.lang.String[] |
list(java.lang.String path)
Gets a list of all items in the specified folder.
|
boolean |
makeDirectory(java.lang.String path)
Create the specified directory.
|
int |
open(java.lang.String path,
Mode mode)
Opens a file for reading or writing.
|
boolean |
rename(java.lang.String from,
java.lang.String to)
Moves / renames a file or folder.
|
boolean |
setLastModified(java.lang.String path,
long time)
Sets the time a file or folder was supposedly last modified.
|
long |
size(java.lang.String path)
Gets the size of a file.
|
long |
spaceTotal()
The total storage capacity of the file system, in bytes.
|
long |
spaceUsed()
The used storage capacity of the file system, in bytes.
|
load, save
boolean isReadOnly()
open(java.lang.String, li.cil.oc.api.fs.Mode)
should
not allow opening files in write or append mode, makeDirectory(java.lang.String)
and such should do nothing/return false/throw an exception).long spaceTotal()
long spaceUsed()
boolean exists(java.lang.String path)
path
- the path to check at.long size(java.lang.String path)
path
- the path to get the size for.boolean isDirectory(java.lang.String path)
path
- the path to the object to check.long lastModified(java.lang.String path)
path
- the path to the object to get the last modified time of.java.lang.String[] list(java.lang.String path)
path
- the path to the folder to get the contents of.boolean delete(java.lang.String path)
path
- the path to the object to delete.boolean makeDirectory(java.lang.String path)
path
- the path to the directory to create.boolean rename(java.lang.String from, java.lang.String to) throws java.io.FileNotFoundException
from
- the name of the file or folder to move.to
- the location to move the file or folder to.java.io.FileNotFoundException
- if the source is not a file or folder.boolean setLastModified(java.lang.String path, long time)
path
- the path of the object for which to set the modification time.time
- the time the object was supposedly last modified.int open(java.lang.String path, Mode mode) throws java.io.FileNotFoundException
getHandle(int)
to get an abstract wrapper for
the handle, and to allow interaction with the file.
It is the responsibility of the file system to restore all handles to
their previous state when it is reloaded (game loaded for example).
Important: you should return a random value as the handle, to
reduce the chance for conflicts. For example, a file system may be used
in a compound of file systems (e.g. for the ROM of machines), in which
case it is essential that the handles from different sub file
systems do not overlap.path
- the path to the file to open.mode
- the mode in which to open the file.java.io.FileNotFoundException
- if the object is not a file, or
the file cannot be opened in the
specified mode.Handle getHandle(int handle)
open(java.lang.String, li.cil.oc.api.fs.Mode)
.
The wrapper allows interaction with the underlying file (stream) based
on the mode it was opened in. See Handle
for more details.
If there is no such handle, this should return null, but never
throw.handle
- the ID of the handle to get the wrapper for.void close()
FileSystem
this
will be called whenever the node is disconnected from its network. If
the node was used to represent an item (which will be the usual use-case,
I imagine) this means the item was removed from its container (e.g. hard
drive from a computer) or the container was unloaded.