Package com.djrapitops.plan.storage.file
Interface Resource
- All Known Implementing Classes:
FileResource
,JarResource
,StringCachingResource
,StringResource
public interface Resource
Interface for accessing plugin resources in jar or plugin files.
-
Method Summary
Modifier and TypeMethodDescriptionbyte[]
asBytes()
Get the resource as an InputStream.asLines()
Get the resource as lines.default <T> T
asParsed
(com.google.gson.Gson gson, com.google.gson.reflect.TypeToken<T> token) asString()
Get the resource as a String with each line separated by CRLF newline characters\r\n
.default WebResource
Map to a WebResource used byResourceService
APIs.long
Get the name of this Resource.static boolean
isTextResource
(String resourceName) Check if a resource is a text based file.
-
Method Details
-
getResourceName
String getResourceName()Get the name of this Resource.- Returns:
- Relative file path given to
PlanFiles
.
-
getLastModifiedDate
long getLastModifiedDate() -
asBytes
- Throws:
IOException
-
asInputStream
Get the resource as an InputStream.- Returns:
- InputStream of the resource, not closed automatically.
- Throws:
IOException
- If the resource is unavailable.
-
asLines
Get the resource as lines.- Returns:
- Lines of the resource file.
- Throws:
IOException
- If the resource is unavailable.
-
asString
Get the resource as a String with each line separated by CRLF newline characters\r\n
.- Returns:
- Flat string with each line separated by
\r\n
. - Throws:
IOException
- If the resource is unavailable.
-
asParsed
default <T> T asParsed(com.google.gson.Gson gson, com.google.gson.reflect.TypeToken<T> token) throws IOException - Throws:
IOException
-
asWebResource
Map to a WebResource used byResourceService
APIs.- Returns:
- The resource
- Throws:
UncheckedIOException
- if fails to read the file.
-
isTextResource
Check if a resource is a text based file.- Parameters:
resourceName
- Name of the resource- Returns:
- true if the resource is text based.
-