HTTP body value. Allows to access HTTP body as string, byte[], stream, etc..
HTTP body can be read it only once per request. Attempt to read more than one resulted in unexpected behaviour.
- Since:
- 2.0.0
- Author:
- edgar
-
Method Summary
Modifier and TypeMethodDescriptionbyte[]
bytes()
HTTP body as byte array.channel()
Body as readable channel.static Body
Empty body.long
getSize()
Size in bytes.boolean
True if body is on memory.static Body
Creates a HTTP body from byte array.static Body
of
(Context ctx, InputStream stream, long size) Creates a HTTP body from input stream.static Body
Creates a HTTP body from file.stream()
Body as input stream.default <T> T
Convert this value to the given type.<T> T
Convert this body into the given type.toList()
Get list of values.default <T> List<T>
Get list of the given type.default <T> T
toNullable
(Class<T> type) Convert this value to the given type.<T> T
toNullable
(Type type) Convert this body into the given type.toSet()
Get set of values.default String
HTTP body as string.Methods inherited from interface java.lang.Iterable
forEach, spliterator
Methods inherited from interface io.jooby.Value
booleanValue, booleanValue, byteValue, byteValue, doubleValue, doubleValue, floatValue, floatValue, intValue, intValue, isArray, isMissing, isObject, isPresent, isSingle, longValue, longValue, name, toEnum, toEnum, toMap, toMultimap, toOptional, toOptional, toSet, value, value, value, valueOrNull
-
Method Details
-
value
HTTP body as string.- Parameters:
charset
- Charset.- Returns:
- Body as string.
-
bytes
@NonNull byte[] bytes()HTTP body as byte array.- Returns:
- Body as byte array.
-
isInMemory
boolean isInMemory()True if body is on memory. False, indicates body is on file system. Body larger thanServerOptions.getMaxRequestSize()
will be dump to disk.- Returns:
- True if body is on memory. False, indicates body is on file system.
-
getSize
long getSize()Size in bytes. This is the same asContent-Length
header.- Returns:
- Size in bytes. This is the same as
Content-Length
header.
-
channel
Body as readable channel.- Returns:
- Body as readable channel.
-
stream
Body as input stream.- Returns:
- Body as input stream.
-
toList
Description copied from interface:Value
Get list of the given type. -
toList
Description copied from interface:Value
Get list of values. -
toSet
Description copied from interface:Value
Get set of values. -
to
Description copied from interface:Value
Convert this value to the given type. Support values are single-value, array-value and object-value. Object-value can be converted to a JavaBean type. -
toNullable
Description copied from interface:Value
Convert this value to the given type. Support values are single-value, array-value and object-value. Object-value can be converted to a JavaBean type.- Specified by:
toNullable
in interfaceValue
- Type Parameters:
T
- Element type.- Parameters:
type
- Type to convert.- Returns:
- Instance of the type or
null
.
-
to
Convert this body into the given type.- Type Parameters:
T
- Generic type.- Parameters:
type
- Type to use.- Returns:
- Converted value.
-
toNullable
Convert this body into the given type.- Type Parameters:
T
- Generic type.- Parameters:
type
- Type to use.- Returns:
- Converted value or
null
.
-
empty
Empty body.- Parameters:
ctx
- Current context.- Returns:
- Empty body.
-
of
Creates a HTTP body from input stream.- Parameters:
ctx
- Current context.stream
- Input stream.size
- Size in bytes or-1
.- Returns:
- A new body.
-
of
Creates a HTTP body from byte array.- Parameters:
ctx
- Current context.bytes
- byte array.- Returns:
- A new body.
-
of
Creates a HTTP body from file.- Parameters:
ctx
- Current context.file
- File.- Returns:
- A new body.
-