public interface WebBody
Created by covers1624 on 1/8/23.
| Modifier and Type | Interface and Description |
|---|---|
static class |
WebBody.BytesBody
Simple
WebBody implementation reading from
an in-memory, byte[]. |
static class |
WebBody.PathBody |
| Modifier and Type | Method and Description |
|---|---|
default byte[] |
asBytes()
Read the body as a byte array.
|
default java.lang.String |
asString()
Reads the body as a UTF-8 String.
|
default java.lang.String |
asString(java.nio.charset.Charset charset)
Read the body as a String.
|
static WebBody |
bytes(byte[] bytes)
Create a
WebBody form a byte[]. |
static WebBody |
bytes(byte[] bytes,
@Nullable java.lang.String contentType)
Create a
WebBody form a byte[]. |
@Nullable java.lang.String |
contentType()
The mime content type for this data.
|
long |
length()
The length of the data.
|
boolean |
multiOpenAllowed()
Checks if this WebBody supports
open() being
called multiple times. |
java.io.InputStream |
open()
Open a stream to read the body data.
|
default java.nio.channels.ReadableByteChannel |
openChannel()
Open a byte channel into a body data.
|
static WebBody |
path(java.nio.file.Path path)
Create a
WebBody for a Path. |
static WebBody |
path(java.nio.file.Path path,
@Nullable java.lang.String contentType)
Create a
WebBody for a Path. |
static WebBody |
string(java.lang.String str)
Create a
WebBody from a String. |
static WebBody |
string(java.lang.String str,
java.nio.charset.Charset charset)
Create a
WebBody from a String. |
static WebBody |
string(java.lang.String str,
java.nio.charset.Charset charset,
@Nullable java.lang.String contentType)
Create a
WebBody from a String. |
static WebBody |
string(java.lang.String str,
@Nullable java.lang.String contentType)
Create a
WebBody from a String. |
java.io.InputStream open()
throws java.io.IOException
java.io.IOException - If an IO error occurs.default java.nio.channels.ReadableByteChannel openChannel()
throws java.io.IOException
If the underlying data does not support Channels,
the open() InputStream will be wrapped
to a ReadableByteChannel.
java.io.IOException - If an IO error occurs.boolean multiOpenAllowed()
open() being
called multiple times.long length()
-1 for unknown.@Nullable @Nullable java.lang.String contentType()
default byte[] asBytes()
throws java.io.IOException
java.io.IOExceptiondefault java.lang.String asString()
throws java.io.IOException
java.io.IOExceptiondefault java.lang.String asString(java.nio.charset.Charset charset)
throws java.io.IOException
java.io.IOExceptionstatic WebBody string(java.lang.String str)
WebBody from a String.
This method assumes null contentType
This method assumes StandardCharsets.UTF_8 charset.str - The string.WebBody.static WebBody string(java.lang.String str, @Nullable @Nullable java.lang.String contentType)
str - The string.contentType - The Content-Type for the body.WebBody.static WebBody string(java.lang.String str, java.nio.charset.Charset charset)
str - The string.charset - The Charset for the body.WebBody.static WebBody string(java.lang.String str, java.nio.charset.Charset charset, @Nullable @Nullable java.lang.String contentType)
WebBody from a String.str - The string.charset - The Charset for the body.contentType - The Content-Type for the body.WebBody.static WebBody bytes(byte[] bytes, @Nullable @Nullable java.lang.String contentType)
WebBody form a byte[].bytes - The bytes.contentType - The Content-Type for the body.WebBody