Class ReadableEntityBase

java.lang.Object
io.helidon.http.media.ReadableEntityBase
All Implemented Interfaces:
ReadableEntity
Direct Known Subclasses:
ClientResponseEntity, Http2ServerRequestEntity, ServerRequestEntity

public abstract class ReadableEntityBase extends Object implements ReadableEntity
Base for readable entities.
  • Constructor Details

    • ReadableEntityBase

      protected ReadableEntityBase(Function<Integer,BufferData> readEntityFunction, Runnable entityProcessedRunnable)
      Create a new base.
      Parameters:
      readEntityFunction - accepts estimate of needed bytes, returns buffer data (the length of buffer data may differ from the estimate)
      entityProcessedRunnable - runnable to run when entity is fully read
    • ReadableEntityBase

      protected ReadableEntityBase(Consumer<Boolean> entityRequestedCallback, Function<Integer,BufferData> readEntityFunction, Runnable entityProcessedRunnable)
  • Method Details

    • empty

      public static ReadableEntity empty()
      Create a new empty readable entity (when there is no entity).
      Returns:
      empty readable entity
    • inputStream

      public InputStream inputStream()
      Description copied from interface: ReadableEntity
      Input stream to read bytes of the entity. Cannot be combined with methods ReadableEntity.as(Class) or ReadableEntity.as(io.helidon.common.GenericType)
      Specified by:
      inputStream in interface ReadableEntity
      Returns:
      input stream to entity bytes
    • as

      public <T> T as(Class<T> type)
      Description copied from interface: ReadableEntity
      Get the entity as a specific class. The entity will use MediaContext to find correct media mapper.
      Specified by:
      as in interface ReadableEntity
      Type Parameters:
      T - type of the entity
      Parameters:
      type - class of the entity
      Returns:
      entity correctly typed
    • as

      public final <T> T as(GenericType<T> type)
      Description copied from interface: ReadableEntity
      Get the entity as a specific type. The entity will use MediaContext to find correct media mapper.
      Specified by:
      as in interface ReadableEntity
      Type Parameters:
      T - type of the entity
      Parameters:
      type - generic type of the entity
      Returns:
      entity correctly typed
    • consumed

      public boolean consumed()
      Description copied from interface: ReadableEntity
      Whether this entity has been consumed already.
      Specified by:
      consumed in interface ReadableEntity
      Returns:
      true if the entity is already consumed; a consumed entity cannot be consumed again
    • consume

      public void consume()
      Description copied from interface: ReadableEntity
      Consume the entity if not yet consumed. Reads all bytes from the entity and discards them. If entity is larger than allowed, appropriate HTTP exception is thrown. If entity is already consumed, this is a no-op.
      Specified by:
      consume in interface ReadableEntity
    • hasEntity

      public boolean hasEntity()
      Description copied from interface: ReadableEntity
      Whether an entity actually exists.
      Specified by:
      hasEntity in interface ReadableEntity
      Returns:
      true if an entity exists and can be read
    • entityAs

      protected abstract <T> T entityAs(GenericType<T> type)
    • readAllBytes

      protected byte[] readAllBytes()
      Read all bytes of the entity into memory.
      Returns:
      all bytes of the entity
    • readEntityFunction

      protected Function<Integer,BufferData> readEntityFunction()
      Function to request entity bytes.
      Returns:
      function that accepts an integer with a suggestion of how many bytes are requested, and returns a buffer
    • entityProcessedRunnable

      protected Runnable entityProcessedRunnable()
      Runnable to run once the entity is fully consumed.
      Returns:
      runnable to run on consumed