Package com.linecorp.armeria.common
Interface HttpData
- All Superinterfaces:
AutoCloseable,HttpObject,SafeCloseable
HTTP/2 data that contains a chunk of bytes.
-
Method Summary
Modifier and TypeMethodDescriptionbyte[]array()Returns the underlying byte array of this data.default ByteBufbyteBuf()(Advanced users only) Returns a new duplicate of the underlyingByteBufof this data.byteBuf(int offset, int length, ByteBufAccessMode mode)(Advanced users only) Returns a new slice, retained slice or direct copy of the underlyingByteBufof this data based on the specifiedByteBufAccessMode.byteBuf(ByteBufAccessMode mode)(Advanced users only) Returns a new duplicate, retained duplicate or direct copy of the underlyingByteBufof this data based on the specifiedByteBufAccessMode.voidclose()Releases the underlyingByteBufif this data was created viawrap(ByteBuf).static HttpDatacopyOf(byte[] data)Creates a new instance from the specified byte array by first copying it.static HttpDatacopyOf(byte[] data, int offset, int length)Creates a new instance from the specified byte array,offsetandlengthby first copying it.static HttpDataCreates a new instance from the specifiedByteBufby first copying its content.static HttpDataempty()Returns an emptyHttpData.default booleanisEmpty()Returns whether thelength()of this data is 0.booleanisPooled()(Advanced users only) Returns whether this data is pooled.intlength()Returns the length of this data.static HttpDataof(Charset charset, CharSequence text)Converts the specifiedtextinto anHttpData.static HttpDataConverts the specifiedtextinto anHttpData.static HttpDataConverts the specified formatted string into anHttpData.static HttpDataofAscii(CharSequence text)Converts the specifiedtextinto a US-ASCIIHttpData.static HttpDataConverts the specifiedtextinto a US-ASCIIHttpData.static HttpDataConverts the specified formatted string into a US-ASCIIHttpData.static HttpDataofUtf8(CharSequence text)Converts the specifiedtextinto a UTF-8HttpData.static HttpDataConverts the specifiedtextinto a UTF-8HttpData.static HttpDataConverts the specified formatted string into a UTF-8HttpData.Returns a newInputStreamthat is sourced from this data.default Readerdefault ReaderReturns a newReaderthat is sourced from this data and decoded usingStandardCharsets.US_ASCII.default ReaderReturns a newReaderthat is sourced from this data and decoded usingStandardCharsets.UTF_8.Decodes this data into aString.default StringDecodes this data into aStringusing US-ASCII encoding.default StringDecodes this data into aStringusing UTF-8 encoding.default void(Advanced users only) Records the current access location of this data for debugging purposes.default HttpDataReturns theHttpDatathat has the same content with this data and its HTTP/2endOfStreamflag set.withEndOfStream(boolean endOfStream)Returns theHttpDatathat has the same content with this data and its HTTP/2endOfStreamflag set with the specified value.static HttpDatawrap(byte[] data)Creates a new instance from the specified byte array.static HttpDatawrap(byte[] data, int offset, int length)Creates a new instance from the specified byte array,offsetandlength.static HttpDataMethods inherited from interface com.linecorp.armeria.common.HttpObject
isEndOfStream
-
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,offsetandlength. The array is not copied; any changes made in the array later will be visible toHttpData.- Returns:
- a new
HttpData.empty()iflengthis 0. - Throws:
IndexOutOfBoundsException- ifoffsetandlengthare out of bounds
-
wrap
(Advanced users only) Converts the specified NettyByteBufinto a pooledHttpData. 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()if the readable bytes ofbufis 0. - See Also:
PooledObjects
-
copyOf
Creates a new instance from the specified byte array by first copying it. -
copyOf
Creates a new instance from the specified byte array,offsetandlengthby first copying it.- Returns:
- a new
HttpData.empty()iflengthis 0. - Throws:
ArrayIndexOutOfBoundsException- ifoffsetandlengthare out of bounds
-
copyOf
-
of
Converts the specifiedtextinto anHttpData. -
of
Converts the specifiedtextinto anHttpData. -
of
Converts the specified formatted string into anHttpData. The string is formatted byString.format(Locale, String, Object...)with English locale.- Parameters:
charset- theCharsetto 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()ifformatis empty.
-
ofUtf8
Converts the specifiedtextinto a UTF-8HttpData. -
ofUtf8
Converts the specifiedtextinto 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()ifformatis empty.
-
ofAscii
Converts the specifiedtextinto a US-ASCIIHttpData. -
ofAscii
Converts the specifiedtextinto 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()ifformatis empty.
-
array
byte[] array()Returns the underlying byte array of this data. Any changes made in the returned array affects the content of this data. -
length
int length()Returns the length of this data. -
isEmpty
default boolean isEmpty()Returns whether thelength()of this data is 0. -
toString
Decodes this data into aString. -
toStringUtf8
Decodes this data into aStringusing UTF-8 encoding.- Returns:
- the decoded
String
-
toStringAscii
Decodes this data into aStringusing US-ASCII encoding.- Returns:
- the decoded
String
-
toInputStream
InputStream toInputStream()Returns a newInputStreamthat is sourced from this data. -
toReader
-
toReaderUtf8
Returns a newReaderthat is sourced from this data and decoded usingStandardCharsets.UTF_8. -
toReaderAscii
Returns a newReaderthat is sourced from this data and decoded usingStandardCharsets.US_ASCII. -
withEndOfStream
Returns theHttpDatathat has the same content with this data and its HTTP/2endOfStreamflag set. If this data already hasendOfStreamset,thiswill be returned. -
withEndOfStream
Returns theHttpDatathat has the same content with this data and its HTTP/2endOfStreamflag set with the specified value. If this data already has the sameendOfStreamvalue set,thiswill be returned. -
isPooled
(Advanced users only) Returns whether this data is pooled. Note, if this method returnstrue, you must callclose()once you no longer need this data, because its underlyingByteBufwill not be released automatically.- See Also:
PooledObjects
-
byteBuf
(Advanced users only) Returns a new duplicate of the underlyingByteBufof this data. This method does not transfer the ownership of the underlyingByteBuf, i.e. the reference count of theByteBufdoes not change. If this data is not pooled, the returnedByteBufis not pooled, either, which means you need to worry about releasing it only when you created this data withwrap(ByteBuf). Any changes made in the content of the returnedByteBufaffects the content of this data.- See Also:
PooledObjects
-
byteBuf
(Advanced users only) Returns a new duplicate, retained duplicate or direct copy of the underlyingByteBufof this data based on the specifiedByteBufAccessMode. This method does not transfer the ownership of the underlyingByteBuf, i.e. the reference count of theByteBufdoes not change. If this data is not pooled, the returnedByteBufis not pooled, either, which means you need to worry about releasing it only when you created this data withwrap(ByteBuf). Any changes made in the content of the returnedByteBufaffects the content of this data.- See Also:
PooledObjects
-
byteBuf
(Advanced users only) Returns a new slice, retained slice or direct copy of the underlyingByteBufof this data based on the specifiedByteBufAccessMode. This method does not transfer the ownership of the underlyingByteBuf, i.e. the reference count of theByteBufdoes not change. If this data is not pooled, the returnedByteBufis not pooled, either, which means you need to worry about releasing it only when you created this data withwrap(ByteBuf). Any changes made in the content of the returnedByteBufaffects the content of this data.- See Also:
PooledObjects
-
touch
(Advanced users only) Records the current access location of this data for debugging purposes. If this data is determined to be leaked, the information recorded by this operation will be provided to you viaResourceLeakDetector. -
close
void close()Releases the underlyingByteBufif this data was created viawrap(ByteBuf). Otherwise, this method does nothing. You may want to call this method to reclaim the underlyingByteBufwhen using operations that return pooled objects, such as: If you don't use such operations, you don't need to call this method.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceSafeCloseable- See Also:
PooledObjects
-