Resource

open class Resource(val resourcePath: String, val loadSync: Boolean = "http" !in resourcePath)

representation of a resource, which can be loaded asynchronously or synchronously.

For the definition of a resource, see getResourceStream.

Since

1.1.6

See also

Inheritors

Constructors

Link copied to clipboard
constructor(resourcePath: String, loadSync: Boolean = "http" !in resourcePath)

Properties

Link copied to clipboard
@get:JvmName(name = "shouldLoadSync")
val loadSync: Boolean

true if this resource should be loaded synchronously, false otherwise. (optional operation)

Link copied to clipboard

Functions

Link copied to clipboard
open fun bytes(): ByteArray

Return this resource's contents as an array of bytes.

Link copied to clipboard
open operator override fun equals(other: Any?): Boolean
Link copied to clipboard
open override fun hashCode(): Int
Link copied to clipboard
inline fun load(errorHandler: (Throwable) -> ByteArray = { throw it }): ByteArray

load the given resource synchronously into a new byte array. you may then perform any operations on the result.

inline fun <T> load(errorHandler: (Throwable) -> T & Any = { throw it }, mapper: (ByteArray) -> T & Any): T

load the given resource synchronously, mapping to definitely non-nullable type T. you may then perform any operations on the result.

Link copied to clipboard
fun loadAsync(errorHandler: (Throwable) -> Unit = { throw it }, consumer: (ByteArray) -> Unit)

load the given resource asynchronously into a new byte array, calling the consumer with the result on the worker thread.

fun <T> loadAsync(errorHandler: (Throwable) -> Unit = { throw it }, mapper: (ByteArray) -> T & Any, consumer: (T & Any) -> Unit)

load the given resource asynchronously, mapping to definitely non-nullable type T, calling the consumer with the result on the worker thread.

Link copied to clipboard
fun onInit(func: () -> Unit)

Add a callback that will be executed once this resource has been successfully initialized by a rendering implementation.

Link copied to clipboard
@ApiStatus.Internal
fun reportInit()

Use this method to execute any callbacks that were added before the resource was initialized.

Link copied to clipboard
open fun stream(): InputStream

return the stream of this resource. it is the caller's responsibility to close the stream.

Link copied to clipboard
open override fun toString(): String