Interface Bytes

All Superinterfaces:
AutoCloseable, SafeCloseable
All Known Subinterfaces:
CloseWebSocketFrame, HttpData, WebSocketFrame

@UnstableApi public interface Bytes extends SafeCloseable
Represents binary data.
  • 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 the length() of this data is 0.
    • toString

      String toString(Charset charset)
      Decodes this data into a String.
      Parameters:
      charset - the Charset to use for decoding this data
      Returns:
      the decoded String
    • toStringUtf8

      default String toStringUtf8()
      Decodes this data into a String using UTF-8 encoding.
      Returns:
      the decoded String
    • toStringAscii

      default String toStringAscii()
      Decodes this data into a String using US-ASCII encoding.
      Returns:
      the decoded String
    • toInputStream

      InputStream toInputStream()
      Returns a new InputStream that is sourced from this data.
    • toReader

      default Reader toReader(Charset charset)
      Returns a new Reader that is sourced from this data and decoded using the specified Charset.
    • toReaderUtf8

      default Reader toReaderUtf8()
      Returns a new Reader that is sourced from this data and decoded using StandardCharsets.UTF_8.
    • toReaderAscii

      default Reader toReaderAscii()
      Returns a new Reader that is sourced from this data and decoded using StandardCharsets.US_ASCII.
    • isPooled

      boolean isPooled()
      (Advanced users only) Returns whether this data is pooled. Note, if this method returns true, you must call close() once you no longer need this data, because its underlying ByteBuf will not be released automatically.
      See Also:
    • byteBuf

      default io.netty.buffer.ByteBuf byteBuf()
      (Advanced users only) Returns a new duplicate of the underlying ByteBuf of this data. This method does not transfer the ownership of the underlying ByteBuf, i.e. the reference count of the ByteBuf does not change. If this data is not pooled, the returned ByteBuf 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 returned ByteBuf affects the content of this data.
      See Also:
    • byteBuf

      io.netty.buffer.ByteBuf byteBuf(ByteBufAccessMode mode)
      (Advanced users only) Returns a new duplicate, retained duplicate or direct copy of the underlying ByteBuf of this data based on the specified ByteBufAccessMode. This method does not transfer the ownership of the underlying ByteBuf, i.e. the reference count of the ByteBuf does not change. If this data is not pooled, the returned ByteBuf 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 returned ByteBuf affects the content of this data.
      See Also:
    • byteBuf

      io.netty.buffer.ByteBuf byteBuf(int offset, int length, ByteBufAccessMode mode)
      (Advanced users only) Returns a new slice, retained slice or direct copy of the underlying ByteBuf of this data based on the specified ByteBufAccessMode. This method does not transfer the ownership of the underlying ByteBuf, i.e. the reference count of the ByteBuf does not change. If this data is not pooled, the returned ByteBuf 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 returned ByteBuf affects the content of this data.
      See Also:
    • touch

      default void touch(@Nullable @Nullable Object hint)
      (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 via ResourceLeakDetector.
    • close

      void close()
      Releases the underlying ByteBuf if this data was created with pooled objects. Otherwise, this method does nothing. You may want to call this method to reclaim the underlying ByteBuf when 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:
      close in interface AutoCloseable
      Specified by:
      close in interface SafeCloseable
      See Also: