- 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 TypeMethodDescription<T> T
as
(GenericType<T> type) Get the entity as a specific type.default <T> T
Get the entity as a specific class.<T> Optional
<T> asOptional
(GenericType<T> type) Get the entity as a specific type (optional).default <T> Optional
<T> asOptional
(Class<T> type) Get the entity as a specific class (optional).default void
consume()
Consume the entity if not yet consumed.boolean
consumed()
Whether this entity has been consumed already.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 methodsas(Class)
oras(io.helidon.common.GenericType)
If there is no entity, returns input stream on empty byte array.- Returns:
- input stream to entity bytes
-
as
Get the entity as a specific class. The entity will useMediaContext
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 supportedIllegalStateException
- in case there is no entityUncheckedIOException
- in case I/O fails
-
asOptional
Get the entity as a specific class (optional). The entity will useMediaContext
to find correct media mapper.- Type Parameters:
T
- type of the entity- Parameters:
type
- class of the entity- Returns:
- entity correctly typed, or an empty optional if entity is not present
- Throws:
IllegalArgumentException
- in case the entity type is not supportedUncheckedIOException
- in case I/O fails
-
as
Get the entity as a specific type. The entity will useMediaContext
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 supportedIllegalStateException
- in case there is no entityUncheckedIOException
- in case I/O fails
-
asOptional
Get the entity as a specific type (optional). The entity will useMediaContext
to find correct media mapper.- Type Parameters:
T
- type of the entity- Parameters:
type
- generic type of the entity- Returns:
- entity correctly typed, or an empty optional if entity is not present
- Throws:
IllegalArgumentException
- in case the entity type is not supportedUncheckedIOException
- 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
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.
-