Enum Class ByteBufAccessMode

java.lang.Object
java.lang.Enum<ByteBufAccessMode>
com.linecorp.armeria.common.ByteBufAccessMode
All Implemented Interfaces:
Serializable, Comparable<ByteBufAccessMode>, Constable

@UnstableApi public enum ByteBufAccessMode extends Enum<ByteBufAccessMode>
Specifies the way a ByteBuf is retrieved from a Bytes, such as HttpData or WebSocketFrame.
  • Enum Constant Details

    • DUPLICATE

      public static final ByteBufAccessMode DUPLICATE
      Gets the duplicate (or slice) of the underlying ByteBuf. This mode is useful when you access the ByteBuf within the life cycle of the Bytes, such as HttpData or WebSocketFrame:
      
       try (HttpData content = ...) {
           ByteBuf buf = content.byteBuf(ByteBufAccessMode.DUPLICATE);
           // Read something from 'buf' here.
       }
       // WebSocket frame.
       try (WebSocketFrame frame = ...) {
           ByteBuf buf = frame.byteBuf(ByteBufAccessMode.DUPLICATE);
           // Read something from 'buf' here.
       }
       
      See Also:
      • ByteBuf.duplicate()
      • ByteBuf.slice()
    • RETAINED_DUPLICATE

      public static final ByteBufAccessMode RETAINED_DUPLICATE
      Gets the retained duplicate (or slice) of the underlying ByteBuf. This mode is useful when you access the ByteBuf beyond the life cycle of the Bytes, such as HttpData or WebSocketFrame, by creating another Bytes that shares the ByteBuf's memory region:
      
       HttpData data1 = HttpData.wrap(byteBuf);
       HttpData data2 = HttpData.wrap(data1.byteBuf(ByteBufAccessMode.RETAINED_DUPLICATE));
      
       WebSocketFrame binaryFrame1 = WebSocketFrame.ofPooledBinary(byteBuf);
       WebSocketFrame binaryFrame2 = WebSocketFrame.ofPooledBinary(
           binaryFrame1.byteBuf(ByteBufAccessMode.RETAINED_DUPLICATE));
       
      See Also:
      • ByteBuf.retainedDuplicate()
      • ByteBuf.retainedSlice()
    • FOR_IO

      public static final ByteBufAccessMode FOR_IO
      Converts the underlying ByteBuf into a direct ByteBuf if necessary. If the underlying ByteBuf is already direct, it behaves same with RETAINED_DUPLICATE. Otherwise, a new direct ByteBuf is allocated and the content of the underlying ByteBuf is copied into it. This access mode is useful when you perform direct I/O or send data to a Netty Channel.
  • Method Details

    • values

      public static ByteBufAccessMode[] values()
      Returns an array containing the constants of this enum class, in the order they are declared.
      Returns:
      an array containing the constants of this enum class, in the order they are declared
    • valueOf

      public static ByteBufAccessMode valueOf(String name)
      Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum class has no constant with the specified name
      NullPointerException - if the argument is null