java.lang.Object
net.luis.utils.resources.ResourceLocation
net.luis.utils.resources.ExternalResourceLocation
External implementation of
This class is used to load resources from the filesystem.
ResourceLocation.This class is used to load resources from the filesystem.
-
Nested Class Summary
Nested classes/interfaces inherited from class net.luis.utils.resources.ResourceLocation
ResourceLocation.Type -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final FileThe resource as a file.private final PathThe resource as a path.Fields inherited from class net.luis.utils.resources.ResourceLocation
TEMP -
Constructor Summary
ConstructorsConstructorDescriptionExternalResourceLocation(@Nullable String path, @NotNull String name) Constructs a new external resource location with the given path and name.ExternalResourceLocation(@NotNull Pair<String, String> pair) Constructs a new external resource location from the givenPair.
The first value of the pair is the path, and the second value is the name of the resource. -
Method Summary
Modifier and TypeMethodDescription@NotNull FileasFile()Constructs a newFilefrom the resource.
Resources on the classpath can not be converted into a file.@NotNull PathasPath()Constructs a newPathfrom the resource.
Resources on the classpath cannot be converted into a path.@NotNull Pathcopy()Copies the resource to thetemporary directory.
The copied resource will be deleted on program exit.@NotNull PathCopies the resource to the given target path.
The copied resource will stay on the filesystem and will not be deleted on program exit.
If a temporary copy of the resource is needed useResourceLocation.copy()instead.booleanexists()Checks if the resource exists.byte @NotNull []getBytes()Reads the content of the resource as a byte array.getLines()Reads the content of the resource as a stream of lines.@NotNull InputStreamCreates an input stream to the resource.@NotNull StringReads the content of the resource as a single string.@NotNull ResourceLocation.TypegetType()Returns the type of the resource.protected @NotNull StringmodifyPath(@Nullable String path) Modifies the path of the resource on construction.Methods inherited from class net.luis.utils.resources.ResourceLocation
equals, external, external, getFile, getPath, getResource, getResource, hashCode, internal, internal, splitPath, toString
-
Field Details
-
file
The resource as a file. -
path
The resource as a path.
-
-
Constructor Details
-
ExternalResourceLocation
Constructs a new external resource location from the givenPair.
The first value of the pair is the path, and the second value is the name of the resource.- Parameters:
pair- The pair- Throws:
NullPointerException- If the pair is null
-
ExternalResourceLocation
Constructs a new external resource location with the given path and name.- Parameters:
path- The path of the resourcename- The name of the resource- Throws:
NullPointerException- If the name is null
-
-
Method Details
-
modifyPath
Description copied from class:ResourceLocationModifies the path of the resource on construction.- Specified by:
modifyPathin classResourceLocation- Parameters:
path- The path to modify- Returns:
- The modified path
-
getType
Description copied from class:ResourceLocationReturns the type of the resource.- Specified by:
getTypein classResourceLocation- Returns:
- The type
-
asFile
Description copied from class:ResourceLocationConstructs a newFilefrom the resource.
Resources on the classpath can not be converted into a file.- Specified by:
asFilein classResourceLocation- Returns:
- The resource as a
File
-
asPath
Description copied from class:ResourceLocationConstructs a newPathfrom the resource.
Resources on the classpath cannot be converted into a path.- Specified by:
asPathin classResourceLocation- Returns:
- The resource as a
Path
-
exists
public boolean exists()Description copied from class:ResourceLocationChecks if the resource exists.- Specified by:
existsin classResourceLocation- Returns:
- True if the resource exists, otherwise false
-
getStream
Description copied from class:ResourceLocationCreates an input stream to the resource.- Specified by:
getStreamin classResourceLocation- Returns:
- An input stream
- Throws:
IOException- If an I/O error occurs
-
getBytes
Description copied from class:ResourceLocationReads the content of the resource as a byte array.- Specified by:
getBytesin classResourceLocation- Returns:
- The bytes of the resource
- Throws:
IOException- If an I/O error occurs
-
getString
Description copied from class:ResourceLocationReads the content of the resource as a single string.- Specified by:
getStringin classResourceLocation- Returns:
- The resource content
- Throws:
IOException- If an I/O error occurs
-
getLines
Description copied from class:ResourceLocationReads the content of the resource as a stream of lines.- Specified by:
getLinesin classResourceLocation- Returns:
- The resource content
- Throws:
IOException- If an I/O error occurs
-
copy
Description copied from class:ResourceLocationCopies the resource to thetemporary directory.
The copied resource will be deleted on program exit.- Specified by:
copyin classResourceLocation- Returns:
- The path of the copied resource
- Throws:
IOException- If an I/O error occurs
-
copy
Description copied from class:ResourceLocationCopies the resource to the given target path.
The copied resource will stay on the filesystem and will not be deleted on program exit.
If a temporary copy of the resource is needed useResourceLocation.copy()instead.- Specified by:
copyin classResourceLocation- Parameters:
target- The target path- Returns:
- The path of the copied resource
- Throws:
IOException- If an I/O error occurs
-