Package com.linecorp.armeria.common
Interface Bytes
- All Superinterfaces:
AutoCloseable
,SafeCloseable
- All Known Subinterfaces:
CloseWebSocketFrame
,HttpData
,WebSocketFrame
Represents binary data.
-
Method Summary
Modifier and TypeMethodDescriptionbyte[]
array()
Returns the underlying byte array of this data.default ByteBuf
byteBuf()
(Advanced users only) Returns a new duplicate of the underlyingByteBuf
of this data.byteBuf
(int offset, int length, ByteBufAccessMode mode) (Advanced users only) Returns a new slice, retained slice or direct copy of the underlyingByteBuf
of this data based on the specifiedByteBufAccessMode
.byteBuf
(ByteBufAccessMode mode) (Advanced users only) Returns a new duplicate, retained duplicate or direct copy of the underlyingByteBuf
of this data based on the specifiedByteBufAccessMode
.void
close()
Releases the underlyingByteBuf
if this data was created with pooled objects.default boolean
isEmpty()
Returns whether thelength()
of this data is 0.boolean
isPooled()
(Advanced users only) Returns whether this data is pooled.int
length()
Returns the length of this data.Returns a newInputStream
that is sourced from this data.default Reader
default Reader
Returns a newReader
that is sourced from this data and decoded usingStandardCharsets.US_ASCII
.default Reader
Returns a newReader
that is sourced from this data and decoded usingStandardCharsets.UTF_8
.Decodes this data into aString
.default String
Decodes this data into aString
using US-ASCII encoding.default String
Decodes this data into aString
using UTF-8 encoding.default void
(Advanced users only) Records the current access location of this data for debugging purposes.
-
Method Details
-
array
byte[] array()Returns the underlying byte array of this data. Do not modify the content of the returned byte array. Any changes made in the returned array may or may not affect 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 aString
using UTF-8 encoding.- Returns:
- the decoded
String
-
toStringAscii
Decodes this data into aString
using US-ASCII encoding.- Returns:
- the decoded
String
-
toInputStream
InputStream 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
. -
isPooled
boolean 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 underlyingByteBuf
will not be released automatically.- See Also:
-
byteBuf
(Advanced users only) Returns a new duplicate of the underlyingByteBuf
of this data. This method does not transfer the ownership of the underlyingByteBuf
, i.e. the reference count of theByteBuf
does not change. If this data is not pooled, the returnedByteBuf
is not pooled, either, which means you need to worry about releasing it only when you created this data with pooled objects. Any changes made in the content of the returnedByteBuf
affects the content of this data.- See Also:
-
byteBuf
(Advanced users only) Returns a new duplicate, retained duplicate or direct copy of the underlyingByteBuf
of this data based on the specifiedByteBufAccessMode
. This method does not transfer the ownership of the underlyingByteBuf
, i.e. the reference count of theByteBuf
does not change. If this data is not pooled, the returnedByteBuf
is not pooled, either, which means you need to worry about releasing it only when you created this data with pooled objects. Any changes made in the content of the returnedByteBuf
affects the content of this data.- See Also:
-
byteBuf
(Advanced users only) Returns a new slice, retained slice or direct copy of the underlyingByteBuf
of this data based on the specifiedByteBufAccessMode
. This method does not transfer the ownership of the underlyingByteBuf
, i.e. the reference count of theByteBuf
does not change. If this data is not pooled, the returnedByteBuf
is not pooled, either, which means you need to worry about releasing it only when you created this data with pooled objects. Any changes made in the content of the returnedByteBuf
affects the content of this data.- See Also:
-
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 underlyingByteBuf
if this data was created with pooled objects. Otherwise, this method does nothing. You may want to call this method to reclaim the underlyingByteBuf
when using operations that return pooled objects, such as:StreamMessage.subscribe(Subscriber, SubscriptionOption...)
withSubscriptionOption.WITH_POOLED_OBJECTS
HttpRequest.aggregate(AggregationOptions)
withAggregationOptions.usePooledObjects(ByteBufAllocator)
HttpResponse.aggregate(AggregationOptions)
withAggregationOptions.usePooledObjects(ByteBufAllocator)
HttpFile.aggregateWithPooledObjects(Executor, ByteBufAllocator)
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceSafeCloseable
- See Also:
-