类 Buffer

java.lang.Object
com.weicoder.common.binary.Buffer
所有已实现的接口:
ByteArray

public final class Buffer extends Object implements ByteArray
类说明:数据包类 ,字节缓存类,字节操作高位在前,低位在后
作者:
WD
  • 构造器概要

    构造器
    构造器
    说明
    按默认的大小构造一个字节缓存对象
    Buffer(boolean sync)
    按默认的大小构造一个字节缓存对象
    Buffer(byte[] data)
    按指定的字节数组构造一个字节缓存对象
    Buffer(byte[] data, boolean sync)
    按指定的字节数组构造一个字节缓存对象
    Buffer(byte[] data, int index, int length, boolean sync)
    按指定的字节数组构造一个字节缓存对象
    Buffer(int capacity, boolean sync)
    按指定的大小构造一个字节缓存对象
  • 方法概要

    修饰符和类型
    方法
    说明
    static Buffer
    allocate(int capacity)
    声明个字节缓存
    byte[]
    获得有效数据
    array(byte[] b)
    把字节数组转换成自己的字段
    void
    capacity(int len)
    设置字节缓存的容积,只能扩大容积
    void
    清除字节缓存对象
    void
    压缩缓冲区 抛弃以读数据 并把容量截取到写坐标
    static Buffer
    获得一个空字节缓存
    boolean
    has()
    是否还有任何一个可读字节
    int
    得到字节数组的长度
    int
    得到读数据的偏移量
    void
    offset(int offset)
    设置读数据的偏移量
    byte[]
    read(byte[] data)
    按当前偏移位置读入指定的字节数组
    byte[]
    read(byte[] data, int pos, int len)
    按当前偏移位置读入指定的字节数组
    byte[]
    read(int len)
    按当前偏移位置读入指定的长度的字节数组
    boolean
    读出一个布尔值
    byte
    读出一个字节
    char
    读出一个字符
    double
    读出一个双浮点数值
    float
    读出一个浮点数值
    int
    读出一个整型数值
    long
    读出一个长整型数值
    short
    读出一个短整型数值
    读出一个字符串,长度不超过65534
    readString(int len)
    读出一个指定长度的字符串
    int
    剩余多少可读字节==写偏移量-读偏移量得差值
    int
    top()
    得到写字节的偏移量
    void
    top(int top)
    设置写字节的偏移量
     
    static Buffer
    wrap(byte[] array)
    根据传入的字节数组获得字节缓存
    static Buffer
    wrap(byte[] array, int offset, int length)
    根据传入的字节数组获得字节缓存
    byte[]
    write(byte[] data)
    写入指定字节数组
    byte[]
    write(byte[] data, int pos, int len)
    写入指定字节数组
    void
    writeBoolean(boolean b)
    写入一个布尔值
    void
    writeByte(byte b)
    写入一个字节
    void
    writeChar(char c)
    写入一个字符
    void
    writeDouble(double d)
    写入一个双浮点数值
    void
    writeFloat(float f)
    写入一个浮点数值
    void
    writeInt(int i)
    写入一个整型数值
    void
    writeInt(int i, int pos)
    在指定位置写入一个整型数值,length不变
    void
    writeLong(long l)
    写入一个长整型数值
    void
    writeLong(long l, int pos)
    写入一个长整型数值
    void
    writeShort(int i)
    写入一个短整型数值
    void
    writeShort(short s)
    写入一个短整型数值
    void
    writeShort(short s, int pos)
    在指定位置写入一个短整型数值,length不变
    void
    写入一个字符串,可以为null

    从类继承的方法 java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • 构造器详细资料

    • Buffer

      public Buffer()
      按默认的大小构造一个字节缓存对象
    • Buffer

      public Buffer(boolean sync)
      按默认的大小构造一个字节缓存对象
      参数:
      sync - 是否线程安全
    • Buffer

      public Buffer(int capacity, boolean sync)
      按指定的大小构造一个字节缓存对象
      参数:
      capacity - 初始容量
      sync - 是否线程安全
    • Buffer

      public Buffer(byte[] data)
      按指定的字节数组构造一个字节缓存对象
      参数:
      data - 初始化数组
    • Buffer

      public Buffer(byte[] data, boolean sync)
      按指定的字节数组构造一个字节缓存对象
      参数:
      data - 初始化数组
      sync - 是否线程安全
    • Buffer

      public Buffer(byte[] data, int index, int length, boolean sync)
      按指定的字节数组构造一个字节缓存对象
      参数:
      data - 初始化数组
      index - 读索引
      length - 写索引
      sync - 是否线程安全
  • 方法详细资料

    • allocate

      public static Buffer allocate(int capacity)
      声明个字节缓存
      参数:
      capacity - 缓存容量
      返回:
      字节缓存
    • wrap

      public static Buffer wrap(byte[] array)
      根据传入的字节数组获得字节缓存
      参数:
      array - 字节数组
      返回:
      字节缓存
    • wrap

      public static Buffer wrap(byte[] array, int offset, int length)
      根据传入的字节数组获得字节缓存
      参数:
      array - 字节数组
      offset - 开始的偏移
      length - 数组长度
      返回:
      字节缓存
    • empty

      public static Buffer empty()
      获得一个空字节缓存
      返回:
      空字节缓存
    • capacity

      public void capacity(int len)
      设置字节缓存的容积,只能扩大容积
      参数:
      len - 长度
    • top

      public int top()
      得到写字节的偏移量
      返回:
      偏移
    • top

      public void top(int top)
      设置写字节的偏移量
      参数:
      top - 偏移
    • offset

      public int offset()
      得到读数据的偏移量
      返回:
      偏移
    • offset

      public void offset(int offset)
      设置读数据的偏移量
      参数:
      offset - 偏移
    • remaining

      public int remaining()
      剩余多少可读字节==写偏移量-读偏移量得差值
      返回:
      剩余字节
    • has

      public boolean has()
      是否还有任何一个可读字节
      返回:
      是否可读
    • length

      public int length()
      得到字节数组的长度
      返回:
      长度
    • read

      public byte[] read(int len)
      按当前偏移位置读入指定的长度的字节数组
      参数:
      len - 长度
      返回:
      字节数组
    • read

      public byte[] read(byte[] data)
      按当前偏移位置读入指定的字节数组
      参数:
      data - 指定的字节数组
      返回:
      字节数组
    • read

      public byte[] read(byte[] data, int pos, int len)
      按当前偏移位置读入指定的字节数组
      参数:
      data - 指定的字节数组
      pos - 指定的字节数组的起始位置
      len - 读入的长度
      返回:
      字节数组
    • readBoolean

      public boolean readBoolean()
      读出一个布尔值
      返回:
      boolean
    • readByte

      public byte readByte()
      读出一个字节
      返回:
      字节
    • readChar

      public char readChar()
      读出一个字符
      返回:
      字符
    • readShort

      public short readShort()
      读出一个短整型数值
      返回:
      short
    • readInt

      public int readInt()
      读出一个整型数值
      返回:
      int
    • readFloat

      public float readFloat()
      读出一个浮点数值
      返回:
      float
    • readLong

      public long readLong()
      读出一个长整型数值
      返回:
      long
    • readDouble

      public double readDouble()
      读出一个双浮点数值
      返回:
      double
    • readString

      public String readString(int len)
      读出一个指定长度的字符串
      参数:
      len - 长度
      返回:
      String
    • readString

      public String readString()
      读出一个字符串,长度不超过65534
      返回:
      String
    • write

      public byte[] write(byte[] data)
      写入指定字节数组
      参数:
      data - 指定的字节数组
      返回:
      字节数组
    • write

      public byte[] write(byte[] data, int pos, int len)
      写入指定字节数组
      参数:
      data - 指定的字节数组
      pos - 指定的字节数组的起始位置
      len - 写入的长度
      返回:
      字节数组
    • writeBoolean

      public void writeBoolean(boolean b)
      写入一个布尔值
      参数:
      b - 布尔
    • writeByte

      public void writeByte(byte b)
      写入一个字节
      参数:
      b - 字节
    • writeChar

      public void writeChar(char c)
      写入一个字符
      参数:
      c - 字符
    • writeShort

      public void writeShort(int i)
      写入一个短整型数值
      参数:
      i - int
    • writeShort

      public void writeShort(short s)
      写入一个短整型数值
      参数:
      s - short
    • writeShort

      public void writeShort(short s, int pos)
      在指定位置写入一个短整型数值,length不变
      参数:
      s - short
      pos - 位置
    • writeInt

      public void writeInt(int i)
      写入一个整型数值
      参数:
      i - int
    • writeInt

      public void writeInt(int i, int pos)
      在指定位置写入一个整型数值,length不变
      参数:
      i - int
      pos - 位置
    • writeFloat

      public void writeFloat(float f)
      写入一个浮点数值
      参数:
      f - float
    • writeLong

      public void writeLong(long l)
      写入一个长整型数值
      参数:
      l - long
    • writeLong

      public void writeLong(long l, int pos)
      写入一个长整型数值
      参数:
      l - long
      pos - 位置
    • writeDouble

      public void writeDouble(double d)
      写入一个双浮点数值
      参数:
      d - double
    • writeString

      public void writeString(String s)
      写入一个字符串,可以为null
      参数:
      s - 字符串
    • compact

      public void compact()
      压缩缓冲区 抛弃以读数据 并把容量截取到写坐标
    • array

      public byte[] array()
      获得有效数据
      指定者:
      array 在接口中 ByteArray
      返回:
      字节数组
    • clear

      public void clear()
      清除字节缓存对象
    • array

      public ByteArray array(byte[] b)
      从接口复制的说明: ByteArray
      把字节数组转换成自己的字段
      指定者:
      array 在接口中 ByteArray
      参数:
      b - 要转换的字节数组
      返回:
      一般返回自身 也可以返回副本
    • toString

      public String toString()
      覆盖:
      toString 在类中 Object