java.lang.Object
net.luis.utils.resources.ResourceLocation
net.luis.utils.resources.InternalResourceLocation
Internal implementation of
This class is used to load resources from the classpath.
ResourceLocation
.This class is used to load resources from the classpath.
-
Nested Class Summary
Nested classes/interfaces inherited from class net.luis.utils.resources.ResourceLocation
ResourceLocation.Type
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final URL
The url of the resource on the classpath or null if the resource does not exist.Fields inherited from class net.luis.utils.resources.ResourceLocation
TEMP
-
Constructor Summary
ConstructorsConstructorDescriptionInternalResourceLocation
(@Nullable String path, @NotNull String name) Constructs a new internal resource location with the given path and name.InternalResourceLocation
(@NotNull Pair<String, String> pair) Constructs a new internal 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 File
asFile()
Constructs a newFile
from the resource.
Resources on the classpath can not be converted into a file.@NotNull Path
asPath()
Constructs a newPath
from the resource.
Resources on the classpath cannot be converted into a path.@NotNull Path
copy()
Copies the resource to thetemporary directory
.
The copied resource will be deleted on program exit.@NotNull Path
Copies 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.boolean
exists()
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 InputStream
Creates an input stream to the resource.@NotNull String
Reads the content of the resource as a single string.@NotNull ResourceLocation.Type
getType()
Returns the type of the resource.protected @NotNull String
modifyPath
(@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
-
url
The url of the resource on the classpath or null if the resource does not exist.
-
-
Constructor Details
-
InternalResourceLocation
Constructs a new internal 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
-
InternalResourceLocation
Constructs a new internal 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:ResourceLocation
Modifies the path of the resource on construction.- Specified by:
modifyPath
in classResourceLocation
- Parameters:
path
- The path to modify- Returns:
- The modified path
-
getType
Description copied from class:ResourceLocation
Returns the type of the resource.- Specified by:
getType
in classResourceLocation
- Returns:
- The type
-
asFile
Description copied from class:ResourceLocation
Constructs a newFile
from the resource.
Resources on the classpath can not be converted into a file.- Specified by:
asFile
in classResourceLocation
- Returns:
- The resource as a
File
-
asPath
Description copied from class:ResourceLocation
Constructs a newPath
from the resource.
Resources on the classpath cannot be converted into a path.- Specified by:
asPath
in classResourceLocation
- Returns:
- The resource as a
Path
-
exists
public boolean exists()Description copied from class:ResourceLocation
Checks if the resource exists.- Specified by:
exists
in classResourceLocation
- Returns:
- True if the resource exists, otherwise false
-
getStream
Description copied from class:ResourceLocation
Creates an input stream to the resource.- Specified by:
getStream
in classResourceLocation
- Returns:
- An input stream
- Throws:
IOException
- If an I/O error occurs
-
getBytes
Description copied from class:ResourceLocation
Reads the content of the resource as a byte array.- Specified by:
getBytes
in classResourceLocation
- Returns:
- The bytes of the resource
- Throws:
IOException
- If an I/O error occurs
-
getString
Description copied from class:ResourceLocation
Reads the content of the resource as a single string.- Specified by:
getString
in classResourceLocation
- Returns:
- The resource content
- Throws:
IOException
- If an I/O error occurs
-
getLines
Description copied from class:ResourceLocation
Reads the content of the resource as a stream of lines.- Specified by:
getLines
in classResourceLocation
- Returns:
- The resource content
- Throws:
IOException
- If an I/O error occurs
-
copy
Description copied from class:ResourceLocation
Copies the resource to thetemporary directory
.
The copied resource will be deleted on program exit.- Specified by:
copy
in classResourceLocation
- Returns:
- The path of the copied resource
- Throws:
IOException
- If an I/O error occurs
-
copy
Description copied from class:ResourceLocation
Copies 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:
copy
in classResourceLocation
- Parameters:
target
- The target path- Returns:
- The path of the copied resource
- Throws:
IOException
- If an I/O error occurs
-