Class Resource

  • All Implemented Interfaces:

    
    public class Resource
    
                        

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

    For the definition of a resource, see getResourceStream.

    Since:

    1.1.6

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      final String getResourcePath()
      final Boolean shouldLoadSync() true if this resource should be loaded synchronously, false otherwise.
      InputStream stream() return the stream of this resource.
      ByteArray bytes() Return this resource's contents as an array of bytes.
      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.
      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.
      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.
      final ByteArray load(Function1<Throwable, ByteArray> errorHandler) load the given resource synchronously into a new byte array.
      final Unit onInit(Function0<Unit> func) Add a callback that will be executed once this resource has been successfully initialized by a rendering implementation.
      final Unit reportInit() Use this method to execute any callbacks that were added before the resource was initialized.
      String toString()
      Integer hashCode()
      Boolean equals(Object other)
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

    • Method Detail

      • shouldLoadSync

         final Boolean shouldLoadSync()

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

      • stream

         InputStream stream()

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

      • bytes

         ByteArray bytes()

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

      • 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 has been successfully 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