Enum ByteBufAccessMode

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

@UnstableApi
public enum ByteBufAccessMode
extends Enum<ByteBufAccessMode>
Specifies the way a ByteBuf is retrieved from an HttpData.
  • 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 HttpData:
      
       try (HttpData content = ...) {
           ByteBuf buf = content.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 HttpData, such as creating another HttpData that shares the ByteBuf's memory region:
      
       HttpData data1 = HttpData.wrap(byteBuf);
       HttpData data2 = HttpData.wrap(data1.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 type, in the order they are declared.
      Returns:
      an array containing the constants of this enum type, in the order they are declared
    • valueOf

      public static ByteBufAccessMode valueOf​(String name)
      Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (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 type has no constant with the specified name
      NullPointerException - if the argument is null