public interface HttpData extends HttpObject
Implementations should generally extend AbstractHttpData to interact with other HttpData
implementations.
| Modifier and Type | Field and Description |
|---|---|
static HttpData |
EMPTY_DATA
Deprecated.
Use
empty(). |
| Modifier and Type | Method and 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 and length by first copying
it. |
static HttpData |
copyOf(io.netty.buffer.ByteBuf data)
Creates a new instance from the specified
ByteBuf by first copying it's content. |
static HttpData |
empty()
Returns an empty
HttpData. |
default boolean |
isEmpty()
Returns whether the
length() is 0. |
int |
length()
Returns the length of this data.
|
static HttpData |
of(byte[] data)
Deprecated.
Use
wrap(byte[]). |
static HttpData |
of(byte[] data,
int offset,
int length)
Deprecated.
|
static HttpData |
of(io.netty.buffer.ByteBuf buf)
Deprecated.
Use
copyOf(ByteBuf). |
static HttpData |
of(Charset charset,
CharSequence text)
Converts the specified
text into an HttpData. |
static HttpData |
of(Charset charset,
String text)
Converts the specified
text into an HttpData. |
static HttpData |
of(Charset charset,
String format,
Object... args)
Converts the specified formatted string into an
HttpData. |
static HttpData |
ofAscii(CharSequence text)
Converts the specified
text into a US-ASCII HttpData. |
static HttpData |
ofAscii(String text)
Converts the specified
text into a US-ASCII HttpData. |
static HttpData |
ofAscii(String format,
Object... args)
Converts the specified formatted string into a US-ASCII
HttpData. |
default int |
offset()
Deprecated.
The offset of
HttpData is always 0. |
static HttpData |
ofUtf8(CharSequence text)
Converts the specified
text into a UTF-8 HttpData. |
static HttpData |
ofUtf8(String text)
Converts the specified
text into a UTF-8 HttpData. |
static HttpData |
ofUtf8(String format,
Object... args)
Converts the specified formatted string into a UTF-8
HttpData. |
default InputStream |
toInputStream()
Returns a new
InputStream that is sourced from this data. |
default Reader |
toReader(Charset charset)
|
default Reader |
toReaderAscii()
Returns a new
Reader that is sourced from this data and decoded using
StandardCharsets.US_ASCII. |
default Reader |
toReaderUtf8()
Returns a new
Reader that is sourced from this data and decoded using
StandardCharsets.UTF_8. |
default String |
toString(Charset charset)
Decodes this data into a
String. |
default String |
toStringAscii()
Decodes this data into a
String using US-ASCII encoding. |
default String |
toStringUtf8()
Decodes this data into a
String using UTF-8 encoding. |
HttpData |
withEndOfStream()
Returns a new
HttpData whose HTTP/2 endOfStream flag is set. |
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 and length. |
static HttpData |
wrap(io.netty.buffer.ByteBuf buf)
Converts the specified Netty
ByteBuf into an HttpData. |
isEndOfStream@Deprecated static final HttpData EMPTY_DATA
empty().static HttpData wrap(byte[] data)
HttpData.static HttpData wrap(byte[] data, int offset, int length)
offset and length.
The array is not copied; any changes made in the array later will be visible to HttpData.HttpData. empty() if length is 0.ArrayIndexOutOfBoundsException - if offset and length are out of boundsstatic HttpData wrap(io.netty.buffer.ByteBuf buf)
static HttpData copyOf(byte[] data)
static HttpData copyOf(byte[] data, int offset, int length)
offset and length by first copying
it.HttpData. empty() if length is 0.ArrayIndexOutOfBoundsException - if offset and length are out of boundsstatic HttpData copyOf(io.netty.buffer.ByteBuf data)
ByteBuf by first copying it's content. The reference
count of ByteBuf will not be changed.@Deprecated static HttpData of(byte[] data)
wrap(byte[]).HttpData.@Deprecated static HttpData of(byte[] data, int offset, int length)
wrap(byte[], int, int).offset and length.
The array is not copied; any changes made in the array later will be visible to HttpData.static HttpData of(Charset charset, CharSequence text)
text into an HttpData.@Deprecated static HttpData of(io.netty.buffer.ByteBuf buf)
copyOf(ByteBuf).ByteBuf by first copying it's content. The reference
count of ByteBuf will not be changed.static HttpData of(Charset charset, String format, Object... args)
HttpData. The string is formatted by
String.format(Locale, String, Object...) with English locale.charset - the Charset to use for encoding stringformat - the format string of the response contentargs - the arguments referenced by the format specifiers in the format stringHttpData. empty() if format is empty.static HttpData ofUtf8(CharSequence text)
text into a UTF-8 HttpData.static HttpData ofUtf8(String format, Object... args)
HttpData. The string is formatted by
String.format(Locale, String, Object...) with English locale.format - the format string of the response contentargs - the arguments referenced by the format specifiers in the format stringHttpData. empty() if format is empty.static HttpData ofAscii(CharSequence text)
text into a US-ASCII HttpData.static HttpData ofAscii(String format, Object... args)
HttpData. The string is formatted by
String.format(Locale, String, Object...) with English locale.format - the format string of the response contentargs - the arguments referenced by the format specifiers in the format stringHttpData. empty() if format is empty.byte[] array()
@Deprecated default int offset()
HttpData is always 0.0.int length()
default boolean isEmpty()
length() is 0.default String toStringUtf8()
String using UTF-8 encoding.Stringdefault String toStringAscii()
String using US-ASCII encoding.Stringdefault InputStream toInputStream()
InputStream that is sourced from this data.
Note, if this HttpData is pooled (e.g., it is the result of a call to
HttpResponse.aggregateWithPooledObjects(ByteBufAllocator)), then this InputStream will
increase the reference count of the underlying buffer. Make sure to call InputStream.close(),
usually using a try-with-resources invocation, to release this extra reference. And as usual, don't
forget to call ReferenceCountUtil.release(Object) on this HttpData itself too.
default Reader toReaderUtf8()
Reader that is sourced from this data and decoded using
StandardCharsets.UTF_8.default Reader toReaderAscii()
Reader that is sourced from this data and decoded using
StandardCharsets.US_ASCII.Copyright © 2020 LeanCloud. All rights reserved.