java.lang.Object
io.helidon.http.media.ReadableEntityBase
- All Implemented Interfaces:
ReadableEntity
- Direct Known Subclasses:
ClientResponseEntity,Http2ServerRequestEntity,ServerRequestEntity
Base for readable entities.
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedReadableEntityBase(Consumer<Boolean> entityRequestedCallback, Function<Integer, BufferData> readEntityFunction, Runnable entityProcessedRunnable) Create a new base.protectedReadableEntityBase(Function<Integer, BufferData> readEntityFunction, Runnable entityProcessedRunnable) Create a new base. -
Method Summary
Modifier and TypeMethodDescriptionfinal <T> Tas(GenericType<T> type) Get the entity as a specific type.<T> TGet the entity as a specific class.<T> Optional<T> asOptional(GenericType<T> type) Get the entity as a specific type (optional).voidconsume()Consume the entity if not yet consumed.booleanconsumed()Whether this entity has been consumed already.static ReadableEntityempty()Create a new empty readable entity (when there is no entity).protected abstract <T> TentityAs(GenericType<T> type) Read entity as a specific generic type.protected RunnableRunnable to run once the entity is fully consumed.booleanWhether 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, waitMethods 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
protected ReadableEntityBase(Consumer<Boolean> entityRequestedCallback, Function<Integer, BufferData> readEntityFunction, Runnable entityProcessedRunnable) Create a new base.- Parameters:
entityRequestedCallback- callback invoked when entity is requestedreadEntityFunction- 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
-
-
Method Details
-
empty
Create a new empty readable entity (when there is no entity).- Returns:
- empty readable entity
-
inputStream
Description copied from interface:ReadableEntityInput 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:
inputStreamin interfaceReadableEntity- Returns:
- input stream to entity bytes
-
as
Description copied from interface:ReadableEntityGet the entity as a specific class. The entity will useMediaContextto find correct media mapper.- Specified by:
asin interfaceReadableEntity- Type Parameters:
T- type of the entity- Parameters:
type- class of the entity- Returns:
- entity correctly typed
-
as
Description copied from interface:ReadableEntityGet the entity as a specific type. The entity will useMediaContextto find correct media mapper.- Specified by:
asin interfaceReadableEntity- Type Parameters:
T- type of the entity- Parameters:
type- generic type of the entity- Returns:
- entity correctly typed
-
asOptional
Description copied from interface:ReadableEntityGet the entity as a specific type (optional). The entity will useMediaContextto find correct media mapper.- Specified by:
asOptionalin 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:ReadableEntityWhether this entity has been consumed already.- Specified by:
consumedin interfaceReadableEntity- Returns:
trueif the entity is already consumed; a consumed entity cannot be consumed again
-
consume
public void consume()Description copied from interface:ReadableEntityConsume 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:
consumein interfaceReadableEntity
-
hasEntity
public boolean hasEntity()Description copied from interface:ReadableEntityWhether an entity actually exists.- Specified by:
hasEntityin interfaceReadableEntity- Returns:
trueif an entity exists and can be read
-
entityAs
Read entity as a specific generic type.- Type Parameters:
T- type of the entity- Parameters:
type- type the entity should be coerced into- Returns:
- entity value
-
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
-