public interface HttpData extends HttpObject
HttpData objects that leave the stream open.
To create an HttpData that closes the stream, directly instantiate DefaultHttpData.
Implementations should generally extend AbstractHttpData to interact with other HttpData
implementations.
| Modifier and Type | Field and Description |
|---|---|
static HttpData |
EMPTY_DATA
Empty HTTP/2 data.
|
| 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. |
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. |
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. |
isEndOfStreamstatic final HttpData EMPTY_DATA
static HttpData wrap(byte[] data)
HttpData.HttpData. EMPTY_DATA if the length of the specified array is 0.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_DATA if length is 0.ArrayIndexOutOfBoundsException - if offset and length are out of boundsstatic HttpData wrap(io.netty.buffer.ByteBuf buf)
ByteBuf into an HttpData. The buffer is not copied; any
changes made to it will be visible to HttpData. The ownership of the buffer is transferred to the
HttpData. If you still need to use it after calling this method, make sure to call
ByteBuf.retain() first.HttpData. EMPTY_DATA if the readable bytes of buf is 0.static HttpData copyOf(byte[] data)
HttpData. EMPTY_DATA if the length of the specified array is 0.static HttpData copyOf(byte[] data, int offset, int length)
offset and length by first copying
it.HttpData. EMPTY_DATA 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.HttpData. EMPTY_DATA if the length of the specified array is 0.@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.charset - the Charset to use for encoding texttext - the String to convertHttpData. EMPTY_DATA if the length of text is 0.static HttpData of(Charset charset, String text)
text into an HttpData.charset - the Charset to use for encoding texttext - the String to convertHttpData. EMPTY_DATA if the length of text is 0.@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_DATA if format is empty.static HttpData ofUtf8(CharSequence text)
text into a UTF-8 HttpData.text - the String to convertHttpData. EMPTY_DATA if the length of text is 0.static HttpData ofUtf8(String text)
text into a UTF-8 HttpData.text - the String to convertHttpData. EMPTY_DATA if the length of text is 0.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_DATA if format is empty.static HttpData ofAscii(CharSequence text)
text into a US-ASCII HttpData.text - the String to convertHttpData. EMPTY_DATA if the length of text is 0.static HttpData ofAscii(String text)
text into a US-ASCII HttpData.text - the String to convertHttpData. EMPTY_DATA if the length of text is 0.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_DATA 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.