Package com.linecorp.armeria.common
Interface HttpData
- All Superinterfaces:
HttpObject
- All Known Subinterfaces:
PooledHttpData
- All Known Implementing Classes:
AbstractHttpData
,ByteBufHttpData
public interface HttpData extends HttpObject
HTTP/2 data.
Implementations should generally extend AbstractHttpData
to interact with other HttpData
implementations.
-
Method Summary
Modifier and Type Method Description byte[]
array()
Returns the underlying byte array of this data.static HttpData
copyOf(byte[] data)
Creates a new instance from the specified byte array by first copying it.static HttpData
copyOf(byte[] data, int offset, int length)
Creates a new instance from the specified byte array,offset
andlength
by first copying it.static HttpData
copyOf(ByteBuf data)
Creates a new instance from the specifiedByteBuf
by first copying it's content.static HttpData
empty()
Returns an emptyHttpData
.default boolean
isEmpty()
Returns whether thelength()
is 0.int
length()
Returns the length of this data.static HttpData
of(Charset charset, CharSequence text)
Converts the specifiedtext
into anHttpData
.static HttpData
of(Charset charset, String text)
Converts the specifiedtext
into anHttpData
.static HttpData
of(Charset charset, String format, Object... args)
Converts the specified formatted string into anHttpData
.static HttpData
ofAscii(CharSequence text)
Converts the specifiedtext
into a US-ASCIIHttpData
.static HttpData
ofAscii(String text)
Converts the specifiedtext
into a US-ASCIIHttpData
.static HttpData
ofAscii(String format, Object... args)
Converts the specified formatted string into a US-ASCIIHttpData
.static HttpData
ofUtf8(CharSequence text)
Converts the specifiedtext
into a UTF-8HttpData
.static HttpData
ofUtf8(String text)
Converts the specifiedtext
into a UTF-8HttpData
.static HttpData
ofUtf8(String format, Object... args)
Converts the specified formatted string into a UTF-8HttpData
.default InputStream
toInputStream()
Returns a newInputStream
that is sourced from this data.default Reader
toReader(Charset charset)
default Reader
toReaderAscii()
Returns a newReader
that is sourced from this data and decoded usingStandardCharsets.US_ASCII
.default Reader
toReaderUtf8()
Returns a newReader
that is sourced from this data and decoded usingStandardCharsets.UTF_8
.default String
toString(Charset charset)
Decodes this data into aString
.default String
toStringAscii()
Decodes this data into aString
using US-ASCII encoding.default String
toStringUtf8()
Decodes this data into aString
using UTF-8 encoding.default HttpData
withEndOfStream()
Returns a newHttpData
whose HTTP/2endOfStream
flag is set.HttpData
withEndOfStream(boolean endOfStream)
static HttpData
wrap(byte[] data)
Creates a new instance from the specified byte array.static HttpData
wrap(byte[] data, int offset, int length)
Creates a new instance from the specified byte array,offset
andlength
.static HttpData
wrap(ByteBuf buf)
Deprecated.
-
Method Details
-
empty
Returns an emptyHttpData
. -
wrap
Creates a new instance from the specified byte array. The array is not copied; any changes made in the array later will be visible toHttpData
. -
wrap
Creates a new instance from the specified byte array,offset
andlength
. The array is not copied; any changes made in the array later will be visible toHttpData
.- Returns:
- a new
HttpData
.empty()
iflength
is 0. - Throws:
ArrayIndexOutOfBoundsException
- ifoffset
andlength
are out of bounds
-
wrap
Deprecated.Converts the specified NettyByteBuf
into anHttpData
. The buffer is not copied; any changes made to it will be visible toHttpData
. The ownership of the buffer is transferred to theHttpData
. If you still need to use it after calling this method, make sure to callByteBuf.retain()
first. -
copyOf
Creates a new instance from the specified byte array by first copying it. -
copyOf
Creates a new instance from the specified byte array,offset
andlength
by first copying it.- Returns:
- a new
HttpData
.empty()
iflength
is 0. - Throws:
ArrayIndexOutOfBoundsException
- ifoffset
andlength
are out of bounds
-
copyOf
-
of
Converts the specifiedtext
into anHttpData
. -
of
Converts the specifiedtext
into anHttpData
. -
of
Converts the specified formatted string into anHttpData
. The string is formatted byString.format(Locale, String, Object...)
with English locale.- Parameters:
charset
- theCharset
to use for encoding stringformat
- the format string of the response contentargs
- the arguments referenced by the format specifiers in the format string- Returns:
- a new
HttpData
.empty()
ifformat
is empty.
-
ofUtf8
Converts the specifiedtext
into a UTF-8HttpData
. -
ofUtf8
Converts the specifiedtext
into a UTF-8HttpData
. -
ofUtf8
Converts the specified formatted string into a UTF-8HttpData
. The string is formatted byString.format(Locale, String, Object...)
with English locale.- Parameters:
format
- the format string of the response contentargs
- the arguments referenced by the format specifiers in the format string- Returns:
- a new
HttpData
.empty()
ifformat
is empty.
-
ofAscii
Converts the specifiedtext
into a US-ASCIIHttpData
. -
ofAscii
Converts the specifiedtext
into a US-ASCIIHttpData
. -
ofAscii
Converts the specified formatted string into a US-ASCIIHttpData
. The string is formatted byString.format(Locale, String, Object...)
with English locale.- Parameters:
format
- the format string of the response contentargs
- the arguments referenced by the format specifiers in the format string- Returns:
- a new
HttpData
.empty()
ifformat
is empty.
-
array
byte[] array()Returns the underlying byte array of this data. -
length
int length()Returns the length of this data. -
isEmpty
default boolean isEmpty()Returns whether thelength()
is 0. -
toString
Decodes this data into aString
. -
toStringUtf8
Decodes this data into aString
using UTF-8 encoding.- Returns:
- the decoded
String
-
toStringAscii
Decodes this data into aString
using US-ASCII encoding.- Returns:
- the decoded
String
-
toInputStream
Returns a newInputStream
that is sourced from this data. -
toReader
-
toReaderUtf8
Returns a newReader
that is sourced from this data and decoded usingStandardCharsets.UTF_8
. -
toReaderAscii
Returns a newReader
that is sourced from this data and decoded usingStandardCharsets.US_ASCII
. -
withEndOfStream
Returns a newHttpData
whose HTTP/2endOfStream
flag is set. -
withEndOfStream
-