java.lang.Object
io.helidon.http.media.ReadableEntityBase
- All Implemented Interfaces:
ReadableEntity
- Direct Known Subclasses:
ClientResponseEntity
,Http2ServerRequestEntity
,ServerRequestEntity
Base for readable entities.
-
Constructor Summary
ModifierConstructorDescriptionprotected
ReadableEntityBase
(Consumer<Boolean> entityRequestedCallback, Function<Integer, BufferData> readEntityFunction, Runnable entityProcessedRunnable) protected
ReadableEntityBase
(Function<Integer, BufferData> readEntityFunction, Runnable entityProcessedRunnable) Create a new base. -
Method Summary
Modifier and TypeMethodDescriptionfinal <T> T
as
(GenericType<T> type) Get the entity as a specific type.<T> T
Get the entity as a specific class.<T> Optional
<T> asOptional
(GenericType<T> type) Get the entity as a specific type (optional).void
consume()
Consume the entity if not yet consumed.boolean
consumed()
Whether this entity has been consumed already.static ReadableEntity
empty()
Create a new empty readable entity (when there is no entity).protected abstract <T> T
entityAs
(GenericType<T> type) protected Runnable
Runnable to run once the entity is fully consumed.boolean
Whether an entity actually exists.Input stream to read bytes of the entity.protected byte[]
Read all bytes of the entity into memory.protected Function
<Integer, BufferData> Function to request entity bytes.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface io.helidon.http.media.ReadableEntity
asOptional, copy
-
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
-
-
Method Details
-
empty
Create a new empty readable entity (when there is no entity).- Returns:
- empty readable entity
-
inputStream
Description copied from interface:ReadableEntity
Input stream to read bytes of the entity. Cannot be combined with methodsReadableEntity.as(Class)
orReadableEntity.as(io.helidon.common.GenericType)
If there is no entity, returns input stream on empty byte array.- Specified by:
inputStream
in interfaceReadableEntity
- Returns:
- input stream to entity bytes
-
as
Description copied from interface:ReadableEntity
Get the entity as a specific class. The entity will useMediaContext
to find correct media mapper.- Specified by:
as
in interfaceReadableEntity
- Type Parameters:
T
- type of the entity- Parameters:
type
- class of the entity- Returns:
- entity correctly typed
-
as
Description copied from interface:ReadableEntity
Get the entity as a specific type. The entity will useMediaContext
to find correct media mapper.- Specified by:
as
in interfaceReadableEntity
- Type Parameters:
T
- type of the entity- Parameters:
type
- generic type of the entity- Returns:
- entity correctly typed
-
asOptional
Description copied from interface:ReadableEntity
Get the entity as a specific type (optional). The entity will useMediaContext
to find correct media mapper.- Specified by:
asOptional
in interfaceReadableEntity
- 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
-
consumed
public boolean consumed()Description copied from interface:ReadableEntity
Whether this entity has been consumed already.- Specified by:
consumed
in interfaceReadableEntity
- 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 interfaceReadableEntity
-
hasEntity
public boolean hasEntity()Description copied from interface:ReadableEntity
Whether an entity actually exists.- Specified by:
hasEntity
in interfaceReadableEntity
- Returns:
true
if an entity exists and can be read
-
entityAs
-
readAllBytes
protected byte[] readAllBytes()Read all bytes of the entity into memory.- Returns:
- all bytes of the entity
-
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
Runnable to run once the entity is fully consumed.- Returns:
- runnable to run on consumed
-