Class SectionBuffer

java.lang.Object
org.miaixz.bus.core.io.SectionBuffer

public class SectionBuffer extends Object
缓冲区的一段 缓冲区中的每个段都是一个循环链表节点,它引用以下内容和 缓冲区中前面的段 池中的每个段都是一个单链列表节点,引用池 段的底层字节数组可以在缓冲区和字节字符串之间共享 当一个 段不能回收,也不能改变它的字节数据 唯一的例外是允许所有者段附加到段中,写入数据 limit及以上 每个字节数组都有一个单独的拥有段 的立场, 限制、prev和next引用不共享
Since:
Java 17+
Author:
Kimi Liu
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    final byte[]
     
    int
    准备写入的可用数据的第一个字节.
    链表或循环链表中的下一段.
    boolean
    如果这个段拥有字节数组并可以向其追加,则为True,扩展limit.
    int
    此段中要读取的应用程序数据字节的下一个字节.
    循环链表中的前一段.
    static final int
    这样做避免了这么多字节的arraycopy()时,将被共享
    boolean
    如果其他段或字节字符串使用相同的字节数组,则为真.
    static final int
    所有段的大小(以字节为单位)
  • Constructor Summary

    Constructors
    Constructor
    Description
     
    SectionBuffer(byte[] data, int pos, int limit, boolean shared, boolean owner)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
     
    pop()
    Removes this segment of a circularly-linked list and returns its successor.
    Appends segment after this segment in the circularly-linked list.
    Returns a new segment that shares the underlying byte array with this.
    split(int byteCount)
    Splits this head of a circularly-linked list into two segments.
    Returns a new segment that its own private copy of the underlying byte array.
    final void
    writeTo(SectionBuffer sink, int byteCount)
    Moves byteCount bytes from this segment to sink.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • SIZE

      public static final int SIZE
      所有段的大小(以字节为单位)
      See Also:
    • SHARE_MINIMUM

      public static final int SHARE_MINIMUM
      这样做避免了这么多字节的arraycopy()时,将被共享
      See Also:
    • data

      public final byte[] data
    • pos

      public int pos
      此段中要读取的应用程序数据字节的下一个字节.
    • limit

      public int limit
      准备写入的可用数据的第一个字节.
    • shared

      public boolean shared
      如果其他段或字节字符串使用相同的字节数组,则为真.
    • owner

      public boolean owner
      如果这个段拥有字节数组并可以向其追加,则为True,扩展limit.
    • next

      public SectionBuffer next
      链表或循环链表中的下一段.
    • prev

      public SectionBuffer prev
      循环链表中的前一段.
  • Constructor Details

    • SectionBuffer

      public SectionBuffer()
    • SectionBuffer

      public SectionBuffer(byte[] data, int pos, int limit, boolean shared, boolean owner)
  • Method Details

    • sharedCopy

      public final SectionBuffer sharedCopy()
      Returns a new segment that shares the underlying byte array with this. Adjusting pos and limit are safe but writes are forbidden. This also marks the current segment as shared, which prevents it from being pooled.
    • unsharedCopy

      public final SectionBuffer unsharedCopy()
      Returns a new segment that its own private copy of the underlying byte array.
    • pop

      public final SectionBuffer pop()
      Removes this segment of a circularly-linked list and returns its successor. Returns null if the list is now empty.
    • push

      public final SectionBuffer push(SectionBuffer segment)
      Appends segment after this segment in the circularly-linked list. Returns the pushed segment.
    • split

      public final SectionBuffer split(int byteCount)
      Splits this head of a circularly-linked list into two segments. The first segment contains the data in [pos..pos+byteCount). The second segment contains the data in [pos+byteCount..limit). This can be useful when moving partial segments from one buffer to another.

      Returns the new head of the circularly-linked list.

    • compact

      public void compact()
    • writeTo

      public final void writeTo(SectionBuffer sink, int byteCount)
      Moves byteCount bytes from this segment to sink.