java.lang.Object
org.miaixz.bus.core.io.buffer.FastBuffer
org.miaixz.bus.core.io.buffer.FastCharBuffer
- All Implemented Interfaces:
Appendable,CharSequence
快速字符缓冲,将数据存放在缓冲集中,取代以往的单一数组 注意:此缓存在大量重复append时,性能比
StringBuilder要好,但是toArray()性能很差- Since:
- Java 17+
- Author:
- Kimi Liu
-
Field Summary
Fields inherited from class org.miaixz.bus.core.io.buffer.FastBuffer
buffersCount, currentBufferIndex, minChunkLen, offset, size -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionappend(char element) 向快速缓冲加入一个字节append(char[] array) 向快速缓冲加入数据append(char[] array, int off, int len) 向快速缓冲加入数据append(CharSequence csq) append(CharSequence csq, int start, int end) Appends character sequence to buffer.追加字符串append(FastCharBuffer buff) 将另一个快速缓冲加入到自身char[]array(int index) 根据索引位返回缓冲集中的缓冲charcharAt(int index) protected voidensureCapacity(int capacity) 检查现有缓冲区是否满足capacity,不满足则分配新的区域分配下一个缓冲区,不会小于1024charget(int index) 根据索引位返回一个字节voidreset()复位缓冲subSequence(int start, int end) char[]toArray()返回快速缓冲中的数据char[]toArray(int start, int len) 返回快速缓冲中的数据char[]返回快速缓冲中的数据,如果缓冲区中的数据长度固定,则直接返回原始数组
注意此方法共享数组,不能修改数组内容!toString()Methods inherited from class org.miaixz.bus.core.io.buffer.FastBuffer
index, isEmpty, length, offset, sizeMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.CharSequence
chars, codePoints, isEmpty, length
-
Constructor Details
-
FastCharBuffer
public FastCharBuffer()构造 -
FastCharBuffer
public FastCharBuffer(int size) 构造- Parameters:
size- 一个缓冲区的最小字节数
-
-
Method Details
-
append
向快速缓冲加入数据- Parameters:
array- 数据off- 偏移量len- 字节数- Returns:
- 快速缓冲自身 @see FastByteBuffer
-
append
向快速缓冲加入数据- Parameters:
array- 数据- Returns:
- 快速缓冲自身 @see FastByteBuffer
-
append
向快速缓冲加入一个字节- Specified by:
appendin interfaceAppendable- Parameters:
element- 一个字节的数据- Returns:
- 快速缓冲自身 @see FastByteBuffer
-
append
将另一个快速缓冲加入到自身- Parameters:
buff- 快速缓冲- Returns:
- 快速缓冲自身 @see FastByteBuffer
-
array
public char[] array(int index) 根据索引位返回缓冲集中的缓冲- Parameters:
index- 索引位- Returns:
- 缓冲
-
reset
public void reset()Description copied from class:FastBuffer复位缓冲- Overrides:
resetin classFastBuffer
-
toArrayZeroCopyIfPossible
public char[] toArrayZeroCopyIfPossible()返回快速缓冲中的数据,如果缓冲区中的数据长度固定,则直接返回原始数组
注意此方法共享数组,不能修改数组内容!- Returns:
- 快速缓冲中的数据
-
toArray
public char[] toArray()返回快速缓冲中的数据- Returns:
- 快速缓冲中的数据
-
toArray
public char[] toArray(int start, int len) 返回快速缓冲中的数据- Parameters:
start- 逻辑起始位置len- 逻辑字节长- Returns:
- 快速缓冲中的数据
-
get
public char get(int index) 根据索引位返回一个字节- Parameters:
index- 索引位- Returns:
- 一个字节
-
toString
- Specified by:
toStringin interfaceCharSequence- Overrides:
toStringin classObject
-
charAt
public char charAt(int index) - Specified by:
charAtin interfaceCharSequence
-
subSequence
- Specified by:
subSequencein interfaceCharSequence
-
append
- Specified by:
appendin interfaceAppendable
-
append
Appends character sequence to buffer.- Specified by:
appendin interfaceAppendable
-
append
追加字符串- Parameters:
string- String- Returns:
- this
-
ensureCapacity
protected void ensureCapacity(int capacity) Description copied from class:FastBuffer检查现有缓冲区是否满足capacity,不满足则分配新的区域分配下一个缓冲区,不会小于1024- Specified by:
ensureCapacityin classFastBuffer- Parameters:
capacity- 理想缓冲区字节数
-