Package com.linecorp.armeria.common
Interface HttpData
-
- All Superinterfaces:
HttpObject
- All Known Implementing Classes:
AbstractHttpData
,ByteBufHttpData
,DefaultHttpData
public interface HttpData extends HttpObject
HTTP/2 data. Helpers in this class createHttpData
objects that leave the stream open. To create aHttpData
that closes the stream, directly instantiateDefaultHttpData
.Implementations should generally extend
AbstractHttpData
to interact with otherHttpData
implementations.
-
-
Field Summary
Fields Modifier and Type Field Description static HttpData
EMPTY_DATA
Empty HTTP/2 data.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Deprecated Methods 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.default boolean
isEmpty()
Returns whether thelength()
is 0.int
length()
Returns the length of this data.static HttpData
of(byte[] data)
Deprecated.Usewrap(byte[])
.static HttpData
of(byte[] data, int offset, int length)
Deprecated.static HttpData
of(ByteBuf buf)
Deprecated.UsecopyOf(ByteBuf)
.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
.default int
offset()
Deprecated.The offset ofHttpData
is always0
.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.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)
-
Methods inherited from interface com.linecorp.armeria.common.HttpObject
isEndOfStream
-
-
-
-
Field Detail
-
EMPTY_DATA
static final HttpData EMPTY_DATA
Empty HTTP/2 data.
-
-
Method Detail
-
wrap
static HttpData wrap(byte[] data)
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
.- Returns:
- a new
HttpData
.EMPTY_DATA
if the length of the specified array is 0.
-
wrap
static HttpData wrap(byte[] data, int offset, int length)
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_DATA
iflength
is 0. - Throws:
ArrayIndexOutOfBoundsException
- ifoffset
andlength
are out of bounds
-
wrap
static HttpData wrap(ByteBuf buf)
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.- Returns:
- a new
HttpData
.EMPTY_DATA
if the readable bytes ofbuf
is 0.
-
copyOf
static HttpData copyOf(byte[] data)
Creates a new instance from the specified byte array by first copying it.- Returns:
- a new
HttpData
.EMPTY_DATA
if the length of the specified array is 0.
-
copyOf
static HttpData copyOf(byte[] data, int offset, int length)
Creates a new instance from the specified byte array,offset
andlength
by first copying it.- Returns:
- a new
HttpData
.EMPTY_DATA
iflength
is 0. - Throws:
ArrayIndexOutOfBoundsException
- ifoffset
andlength
are out of bounds
-
copyOf
static HttpData copyOf(ByteBuf data)
Creates a new instance from the specifiedByteBuf
by first copying it's content. The reference count ofByteBuf
will not be changed.- Returns:
- a new
HttpData
.EMPTY_DATA
if the length of the specified array is 0.
-
of
@Deprecated static HttpData of(byte[] data)
Deprecated.Usewrap(byte[])
.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
.
-
of
@Deprecated static HttpData of(byte[] data, int offset, int length)
Deprecated.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
.
-
of
static HttpData of(Charset charset, CharSequence text)
Converts the specifiedtext
into anHttpData
.- Parameters:
charset
- theCharset
to use for encodingtext
text
- theString
to convert- Returns:
- a new
HttpData
.EMPTY_DATA
if the length oftext
is 0.
-
of
static HttpData of(Charset charset, String text)
Converts the specifiedtext
into anHttpData
.- Parameters:
charset
- theCharset
to use for encodingtext
text
- theString
to convert- Returns:
- a new
HttpData
.EMPTY_DATA
if the length oftext
is 0.
-
of
@Deprecated static HttpData of(ByteBuf buf)
Deprecated.UsecopyOf(ByteBuf)
.
-
of
static HttpData of(Charset charset, String format, Object... args)
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_DATA
ifformat
is empty.
-
ofUtf8
static HttpData ofUtf8(CharSequence text)
Converts the specifiedtext
into a UTF-8HttpData
.- Parameters:
text
- theString
to convert- Returns:
- a new
HttpData
.EMPTY_DATA
if the length oftext
is 0.
-
ofUtf8
static HttpData ofUtf8(String text)
Converts the specifiedtext
into a UTF-8HttpData
.- Parameters:
text
- theString
to convert- Returns:
- a new
HttpData
.EMPTY_DATA
if the length oftext
is 0.
-
ofUtf8
static HttpData ofUtf8(String format, Object... args)
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_DATA
ifformat
is empty.
-
ofAscii
static HttpData ofAscii(CharSequence text)
Converts the specifiedtext
into a US-ASCIIHttpData
.- Parameters:
text
- theString
to convert- Returns:
- a new
HttpData
.EMPTY_DATA
if the length oftext
is 0.
-
ofAscii
static HttpData ofAscii(String text)
Converts the specifiedtext
into a US-ASCIIHttpData
.- Parameters:
text
- theString
to convert- Returns:
- a new
HttpData
.EMPTY_DATA
if the length oftext
is 0.
-
ofAscii
static HttpData ofAscii(String format, Object... args)
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_DATA
ifformat
is empty.
-
array
byte[] array()
Returns the underlying byte array of this data.
-
offset
@Deprecated default int offset()
Deprecated.The offset ofHttpData
is always0
.Returns0
.
-
length
int length()
Returns the length of this data.
-
isEmpty
default boolean isEmpty()
Returns whether thelength()
is 0.
-
toStringUtf8
default String toStringUtf8()
Decodes this data into aString
using UTF-8 encoding.- Returns:
- the decoded
String
-
toStringAscii
default String toStringAscii()
Decodes this data into aString
using US-ASCII encoding.- Returns:
- the decoded
String
-
toInputStream
default InputStream toInputStream()
Returns a newInputStream
that is sourced from this data.Note, if this
HttpData
is pooled (e.g., it is the result of a call toHttpResponse.aggregateWithPooledObjects(ByteBufAllocator)
), then thisInputStream
will increase the reference count of the underlying buffer. Make sure to callInputStream.close()
, usually using a try-with-resources invocation, to release this extra reference. And as usual, don't forget to callReferenceCountUtil.release(Object)
on thisHttpData
itself too.
-
toReaderUtf8
default Reader toReaderUtf8()
Returns a newReader
that is sourced from this data and decoded usingStandardCharsets.UTF_8
.
-
toReaderAscii
default Reader toReaderAscii()
Returns a newReader
that is sourced from this data and decoded usingStandardCharsets.US_ASCII
.
-
-