Package org.aoju.bus.core.io
Class Segment
java.lang.Object
org.aoju.bus.core.io.Segment
缓冲区的一段 缓冲区中的每个段都是一个循环链表节点,它引用以下内容和 缓冲区中前面的段 池中的每个段都是一个单链列表节点,引用池 段的底层字节数组可以在缓冲区和字节字符串之间共享 当一个 段不能回收,也不能改变它的字节数据
唯一的例外是允许所有者段附加到段中,写入数据
limit及以上 每个字节数组都有一个单独的拥有段 的立场, 限制、prev和next引用不共享- Since:
- Java 17+
- Author:
- Kimi Liu
-
Field Summary
FieldsModifier and TypeFieldDescriptionfinal byte[]int准备写入的可用数据的第一个字节.链表或循环链表中的下一段.boolean如果这个段拥有字节数组并可以向其追加,则为True,扩展limit.int此段中要读取的应用程序数据字节的下一个字节.循环链表中的前一段.static final int这样做避免了这么多字节的arraycopy()时,将被共享boolean如果其他段或字节字符串使用相同的字节数组,则为真.static final int所有段的大小(以字节为单位) -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidcompact()final Segmentpop()Removes this segment of a circularly-linked list and returns its successor.final SegmentAppendssegmentafter this segment in the circularly-linked list.final SegmentReturns a new segment that shares the underlying byte array with this.final Segmentsplit(int byteCount) Splits this head of a circularly-linked list into two segments.final SegmentReturns a new segment that its own private copy of the underlying byte array.final voidMovesbyteCountbytes from this segment tosink.
-
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准备写入的可用数据的第一个字节. -
owner
public boolean owner如果这个段拥有字节数组并可以向其追加,则为True,扩展limit. -
next
链表或循环链表中的下一段. -
prev
循环链表中的前一段.
-
-
Constructor Details
-
Segment
public Segment() -
Segment
public Segment(byte[] data, int pos, int limit, boolean shared, boolean owner)
-
-
Method Details
-
pop
Removes this segment of a circularly-linked list and returns its successor. Returns null if the list is now empty. -
push
-
split
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
MovesbyteCountbytes from this segment tosink.