Module bus.core

Class FastBuffer

java.lang.Object
org.miaixz.bus.core.io.buffer.FastBuffer
Direct Known Subclasses:
FastByteBuffer, FastCharBuffer

public abstract class FastBuffer extends Object
快速缓冲抽象类,用于快速读取、写入数据到缓冲区,减少内存复制 相对于普通Buffer,使用二维数组扩展长度,减少内存复制,提升性能
Since:
Java 17+
Author:
Kimi Liu
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected int
    缓冲数
    protected int
    当前缓冲索引
    protected final int
    一个缓冲区的最小字节数
    protected int
    当前缓冲偏移量
    protected int
    缓冲字节数
  • Constructor Summary

    Constructors
    Constructor
    Description
    FastBuffer(int size)
    构造
  • Method Summary

    Modifier and Type
    Method
    Description
    protected abstract void
    ensureCapacity(int capacity)
    检查现有缓冲区是否满足capacity,不满足则分配新的区域分配下一个缓冲区,不会小于1024
    int
    当前缓冲位于缓冲区的索引位
    boolean
    是否为空
    int
    获取缓冲总长度
    int
    获取当前缓冲偏移量
    void
    复位缓冲
    int
    获取缓冲总长度

    Methods inherited from class java.lang.Object

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

    • minChunkLen

      protected final int minChunkLen
      一个缓冲区的最小字节数
    • buffersCount

      protected int buffersCount
      缓冲数
    • currentBufferIndex

      protected int currentBufferIndex
      当前缓冲索引
    • offset

      protected int offset
      当前缓冲偏移量
    • size

      protected int size
      缓冲字节数
  • Constructor Details

    • FastBuffer

      public FastBuffer(int size)
      构造
      Parameters:
      size - 一个缓冲区的最小字节数
  • Method Details

    • index

      public int index()
      当前缓冲位于缓冲区的索引位
      Returns:
      currentBufferIndex
    • offset

      public int offset()
      获取当前缓冲偏移量
      Returns:
      当前缓冲偏移量
    • reset

      public void reset()
      复位缓冲
    • size

      public int size()
      获取缓冲总长度
      Returns:
      缓冲总长度
    • length

      public int length()
      获取缓冲总长度
      Returns:
      缓冲总长度
    • isEmpty

      public boolean isEmpty()
      是否为空
      Returns:
      是否为空
    • ensureCapacity

      protected abstract void ensureCapacity(int capacity)
      检查现有缓冲区是否满足capacity,不满足则分配新的区域分配下一个缓冲区,不会小于1024
      Parameters:
      capacity - 理想缓冲区字节数