Interface ReadableEntity

All Known Subinterfaces:
ReadablePart
All Known Implementing Classes:
ClientResponseEntity, Http2ServerRequestEntity, ReadableEntityBase, ServerRequestEntity

public interface ReadableEntity
Readable HTTP entity. This may be server request entity, or client response entity.
  • Method Summary

    Modifier and Type
    Method
    Description
    <T> T
    as(GenericType<T> type)
    Get the entity as a specific type.
    default <T> T
    as(Class<T> type)
    Get the entity as a specific class.
    default void
    Consume the entity if not yet consumed.
    boolean
    Whether this entity has been consumed already.
    copy(Runnable entityProcessedRunnable)
    Copy this entity and add a new runnable to be executed after this entity is consumed.
    boolean
    Whether an entity actually exists.
    Input stream to read bytes of the entity.
  • Method Details

    • inputStream

      InputStream inputStream()
      Input stream to read bytes of the entity. Cannot be combined with methods as(Class) or as(io.helidon.common.GenericType)
      Returns:
      input stream to entity bytes
    • as

      default <T> T as(Class<T> type)
      Get the entity as a specific class. The entity will use MediaContext to find correct media mapper.
      Type Parameters:
      T - type of the entity
      Parameters:
      type - class of the entity
      Returns:
      entity correctly typed
      Throws:
      IllegalArgumentException - in case the entity type is not supported
      UncheckedIOException - in case I/O fails
    • as

      <T> T as(GenericType<T> type)
      Get the entity as a specific type. The entity will use MediaContext to find correct media mapper.
      Type Parameters:
      T - type of the entity
      Parameters:
      type - generic type of the entity
      Returns:
      entity correctly typed
      Throws:
      IllegalArgumentException - in case the entity type is not supported
      UncheckedIOException - in case I/O fails
    • hasEntity

      boolean hasEntity()
      Whether an entity actually exists.
      Returns:
      true if an entity exists and can be read
    • consumed

      boolean consumed()
      Whether this entity has been consumed already.
      Returns:
      true if the entity is already consumed; a consumed entity cannot be consumed again
    • copy

      ReadableEntity copy(Runnable entityProcessedRunnable)
      Copy this entity and add a new runnable to be executed after this entity is consumed.
      Parameters:
      entityProcessedRunnable - runnable to execute on consumed entity
      Returns:
      a new entity delegating to this entity
    • consume

      default void consume()
      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.