Asset
abstract class Asset
Known subtypes: ClasspathAsset, FileAsset, StreamAsset, UrlAsset
Package: dev.joid.lib.asset · Module: core · Source: Asset.java
Where the bytes of a resource, a font, a shader or a model come from, a file, the classpath, a URL or a stream, behind one stable id.
Description
Section titled “Description”Every loader of JOID takes an Object and turns it into an asset with Asset.of(...): a String path or URL, a File, an InputStream, or an asset you build yourself.
The unique id keys the caches, so two loads of the same asset share their data.
Learn more
Section titled “Learn more”Creation
Section titled “Creation”| Returns | Signature | Summary |
|---|---|---|
Asset | of(Object handle) factory | Returns handle when it is already an asset, otherwise the asset that the registered AssetLocator list finds for it. |
| Asset(String uniqueId) protected | Creates an asset with the id that keys its caches; two assets with the same id are the same content. |
Methods
Section titled “Methods”| Returns | Signature | Summary |
|---|---|---|
File | getFile() | Returns the file on disk that holds the asset, or null when it is not a plain file, such as a resource inside a jar or a URL; a video reads such an asset through a copy in the cache folder. |
boolean | isRemote() | If true, opening the asset goes through the network, so JOID reads it on a background thread. |
byte[] | peek(int length) | Returns the first length bytes of the asset, fewer when it is shorter; the formats use them to recognize a file. |
byte[] | read() | Returns the whole content of the asset. |
String | toString() | Returns the class and the id of the asset, for logs. |
String | getUniqueId() | Returns the id that keys the caches of this asset. |
For subclasses
Section titled “For subclasses”| Returns | Signature | Summary |
|---|---|---|
InputStream | open() hook abstract | Returns a new stream on the content, which the caller closes; JOID calls it each time it reads the asset, possibly from a background thread. |
Creation details
Section titled “Creation details”Asset of(Object handle) factory
Returns handle when it is already an asset, otherwise the asset that the registered AssetLocator list finds for it.
Throws IllegalArgumentException when no locator supports handle, or when a path is found neither in the classpath nor as a file.
Asset(String uniqueId) protected
Creates an asset with the id that keys its caches; two assets with the same id are the same content.
Method details
Section titled “Method details”getFile
Section titled “getFile”File getFile()
Returns the file on disk that holds the asset, or null when it is not a plain file, such as a resource inside a jar or a URL; a video reads such an asset through a copy in the cache folder.
isRemote
Section titled “isRemote”boolean isRemote()
If true, opening the asset goes through the network, so JOID reads it on a background thread.
false by default.
byte[] peek(int length)
Throws:
UncheckedIOException: The start of … cannot be read
Returns the first length bytes of the asset, fewer when it is shorter; the formats use them to recognize a file.
Throws UncheckedIOException when the asset cannot be read.
byte[] read()
Returns the whole content of the asset.
Throws IOException when it cannot be read.
toString
Section titled “toString”String toString()
Returns the class and the id of the asset, for logs.
getUniqueId
Section titled “getUniqueId”String getUniqueId()
Returns the id that keys the caches of this asset.
InputStream open() hook abstract
Returns a new stream on the content, which the caller closes; JOID calls it each time it reads the asset, possibly from a background thread.
Throw IOException when the content cannot be opened.
fluent returns the instance, typed for chaining · factory creates an instance · signal also accepts a value that follows signals, as a signal, an expression or a lambda (When does JOID compute this value again?) · hook called by JOID, override it · abstract you implement it · default interface method with a body · static called on the class · protected visible to subclasses
