Class Resource
-
- All Implemented Interfaces:
public class Resourcerepresentation of a resource, which can be loaded asynchronously or synchronously.
For the definition of a resource, see getResourceStream.
- Since:
1.1.6
-
-
Field Summary
Fields Modifier and Type Field Description private final StringresourcePathprivate final transient BooleanloadSync
-
Method Summary
Modifier and Type Method Description final StringgetResourcePath()final BooleanshouldLoadSync()trueif this resource should be loaded synchronously,falseotherwise.InputStreamstream()return the stream of this resource. ByteArraybytes()Return this resource's contents as an array of bytes. final <T extends Any> UnitloadAsync(Function1<Throwable, Unit> errorHandler, Function1<ByteArray, T> mapper, Function1<T, Unit> consumer)load the given resource asynchronously, mapping to definitely non-nullable type T, calling the consumer with the result on the worker thread. final UnitloadAsync(Function1<Throwable, Unit> errorHandler, Function1<ByteArray, Unit> consumer)load the given resource asynchronously into a new byte array, calling the consumer with the result on the worker thread. final <T extends Any> Tload(Function1<Throwable, T> errorHandler, Function1<ByteArray, T> mapper)load the given resource synchronously, mapping to definitely non-nullable type T. final ByteArrayload(Function1<Throwable, ByteArray> errorHandler)load the given resource synchronously into a new byte array. final UnitonInit(Function0<Unit> func)Add a callback that will be executed once this resource is about to be initialized by a rendering implementation. final UnitreportInit()Use this method to execute any callbacks that were added before the resource was initialized. StringtoString()IntegerhashCode()Booleanequals(Object other)-
-
Method Detail
-
getResourcePath
final String getResourcePath()
-
shouldLoadSync
final Boolean shouldLoadSync()
trueif this resource should be loaded synchronously,falseotherwise. (optional operation)
-
stream
InputStream stream()
return the stream of this resource. it is the caller's responsibility to close the stream.
-
loadAsync
final <T extends Any> Unit loadAsync(Function1<Throwable, Unit> errorHandler, Function1<ByteArray, T> mapper, Function1<T, Unit> consumer)
load the given resource asynchronously, mapping to definitely non-nullable type T, calling the consumer with the result on the worker thread.
In case of failure, the errorHandler will be called with the exception.
- Since:
1.1.6
-
loadAsync
final Unit loadAsync(Function1<Throwable, Unit> errorHandler, Function1<ByteArray, Unit> consumer)
load the given resource asynchronously into a new byte array, calling the consumer with the result on the worker thread.
In case of failure, the errorHandler will be called with the exception.
- Since:
1.1.6
-
load
final <T extends Any> T load(Function1<Throwable, T> errorHandler, Function1<ByteArray, T> mapper)
load the given resource synchronously, mapping to definitely non-nullable type T. you may then perform any operations on the result.
In case of failure, the errorHandler will be called with the exception.
- Since:
1.1.6
-
load
final ByteArray load(Function1<Throwable, ByteArray> errorHandler)
load the given resource synchronously into a new byte array. you may then perform any operations on the result.
In case of failure, the errorHandler will be called with the exception.
- Since:
1.1.6
-
onInit
final Unit onInit(Function0<Unit> func)
Add a callback that will be executed once this resource is about to be initialized by a rendering implementation.
- Since:
1.7.31
-
reportInit
@ApiStatus.Internal() final Unit reportInit()
Use this method to execute any callbacks that were added before the resource was initialized.
This method needs to be called by a rendering implementation at the appropriate time.
- Since:
1.7.31
-
-
-
-