Contents
- Description
- Field Summary
- Method Summary
- Field Details
- Method Details
- setDefaultRoot(Path)
- openFileIOSystem(FS)
- closeFileIOSystem(FileIOSystem)
- exists(AssetPath)
- exists(Path, Path)
- resolve(Path)
- load(AssetPath, AssetLoader)
- load(Path, AssetLoader)
- list(Path, Predicate, UnaryOperator)
- startsWith(Path, Path)
- relativize(Path, Path)
- append(Path, Path)
- equals(Path, Path)
- hashCode(Path)
Interface FileIO
public interface FileIO
API to replace common java.nio.file.Files functions utilizing the FileIOSystem interface.
This allows callers to provide a custom backing FileIOSystem implementation to provide caching
and the ability to locate files across multiple file system roots (such as AssetPacks).
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final it.unimi.dsi.fastutil.Hash.Strategy<Path> Hash strategy for Path objects that works across different file systems. -
Method Summary
Static MethodsModifier and TypeMethodDescriptionstatic PathPath append function that works with Path objects from different file systems.static voidClose and unset the given FileIOSystem if it is the current instance for the current Thread.static booleanPath equals function that works with Path objects from different file systems.static booleanCheck if the given asset path exists.static booleanCheck if the given Path exists under the given root.static intPath hash function that works with Path objects from different file systems.List all paths matching a predicate under a given path.static <T> Tload(AssetPath assetPath, AssetLoader<T> loader) Load a resource from the given path within the current FileIOSystem.static <T> Tload(Path path, AssetLoader<T> loader) Load a resource from the given path within the current FileIOSystem.static <FS extends FileIOSystem>
FSopenFileIOSystem(FS fs) Set the current FileIOSystem to the given instance for the current Thread.static Pathrelativize(Path child, Path parent) Path relativize function that works with Path objects from different file systems.static AssetPathResolve the filepath for a given asset path within the current FileIOSystem.static voidsetDefaultRoot(Path path) Set the default file system's root path.static booleanstartsWith(Path path, Path prefix) Path startsWith function that works with Path objects from different file systems.
-
Field Details
-
PATH_STRATEGY
Hash strategy for Path objects that works across different file systems.
-
-
Method Details
-
setDefaultRoot
Set the default file system's root path.- Parameters:
path- The root path to set.
-
openFileIOSystem
Set the current FileIOSystem to the given instance for the current Thread.- Parameters:
fs- The FileIOSystem instance to set.- Returns:
- The given FileIOSystem instance.
-
closeFileIOSystem
Close and unset the given FileIOSystem if it is the current instance for the current Thread.- Parameters:
fs- The FileIOSystem instance to close.
-
exists
Check if the given asset path exists.- Parameters:
path- The path to check.- Returns:
- True if the path exists, false otherwise.
-
exists
-
resolve
-
load
@Nonnull static <T> T load(@Nonnull AssetPath assetPath, @Nonnull AssetLoader<T> loader) throws IOException Load a resource from the given path within the current FileIOSystem.- Parameters:
assetPath- The assetPath to load the resource from.loader- The loader used to deserialize the file contents.- Returns:
- The loaded resource.
- Throws:
IOException- if the file does not exist or cannot be loaded with the given loader.
-
load
Load a resource from the given path within the current FileIOSystem.- Parameters:
path- The filepath to load the resource from.loader- The loader used to deserialize the file contents.- Returns:
- The loaded resource.
- Throws:
IOException- if the file does not exist or cannot be loaded with the given loader.
-
list
@Nonnull static List<AssetPath> list(@Nonnull Path path, @Nonnull Predicate<AssetPath> matcher, @Nonnull UnaryOperator<AssetPath> disableOp) throws IOException List all paths matching a predicate under a given path. This function iterates all roots in the current FileIOSystem in priority order, collecting (or excluding) the first occurrence of each path found. In addition to the matcher predicate, an operator can be provided to check if a file should be considered disablded/excluded based on its filename formatting. The operator must parse the given path for the specific name formatting that disables the file, and return a new path with that name formatting removed. If the first occurrence of a path is found to be disabled, it will be excluded from the resulting list. A comparator can also be provided to sort the resulting list of paths but must properly handle comparisons of paths originating from different FileSystems.- Parameters:
path- The path to search under.matcher- The predicate to use to positively filter paths.disableOp- Operator used to check and disable a given path.- Returns:
- A list of paths matching the given matcher.
- Throws:
IOException- If an I/O error occurs.
-
startsWith
-
relativize
Path relativize function that works with Path objects from different file systems.- Parameters:
child- The path to relativize against the parent.parent- The parent path to relativize the child against.- Returns:
- The relativized path (ie the child path with the parent path prefix removed).
-
append
-
equals
-
hashCode
Path hash function that works with Path objects from different file systems.- Parameters:
path- The path to hash.- Returns:
- The hashcode of the path.
-