Package com.weicoder.common.binary
Class Buffer
- java.lang.Object
-
- com.weicoder.common.binary.Buffer
-
-
Constructor Summary
Constructors Constructor Description Buffer()按默认的大小构造一个字节缓存对象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)按指定的大小构造一个字节缓存对象
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description byte[]array()获得有效数据ByteArrayarray(byte[] b)把字节数组转换成自己的字段voidcapacity(int len)设置字节缓存的容积,只能扩大容积voidclear()清除字节缓存对象voidcompact()压缩缓冲区 抛弃以读数据 并把容量截取到写坐标booleanhasRemaining()是否还有任何一个可读字节intlength()得到字节数组的长度intoffset()得到读数据的偏移量voidoffset(int offset)设置读数据的偏移量byte[]read(byte[] data)按当前偏移位置读入指定的字节数组byte[]read(byte[] data, int pos, int len)按当前偏移位置读入指定的字节数组byte[]read(int len)按当前偏移位置读入指定的长度的字节数组booleanreadBoolean()读出一个布尔值bytereadByte()读出一个字节charreadChar()读出一个字符doublereadDouble()读出一个双浮点数值floatreadFloat()读出一个浮点数值intreadInt()读出一个整型数值longreadLong()读出一个长整型数值shortreadShort()读出一个短整型数值java.lang.StringreadString()读出一个字符串,长度不超过65534java.lang.StringreadString(int len)读出一个指定长度的字符串intremaining()剩余多少可读字节==写偏移量-读偏移量得差值inttop()得到写字节的偏移量voidtop(int top)设置写字节的偏移量java.lang.StringtoString()byte[]write(byte[] data)写入指定字节数组byte[]write(byte[] data, int pos, int len)写入指定字节数组voidwriteBoolean(boolean b)写入一个布尔值voidwriteByte(byte b)写入一个字节voidwriteChar(char c)写入一个字符voidwriteDouble(double d)写入一个双浮点数值voidwriteFloat(float f)写入一个浮点数值voidwriteInt(int i)写入一个整型数值voidwriteInt(int i, int pos)在指定位置写入一个整型数值,length不变voidwriteLong(long l)写入一个长整型数值voidwriteLong(long l, int pos)写入一个长整型数值voidwriteShort(int i)写入一个短整型数值voidwriteShort(short s)写入一个短整型数值voidwriteShort(short s, int pos)在指定位置写入一个短整型数值,length不变voidwriteString(java.lang.String s)写入一个字符串,可以为null
-
-
-
Constructor Detail
-
Buffer
public Buffer()
按默认的大小构造一个字节缓存对象
-
Buffer
public Buffer(boolean sync)
按默认的大小构造一个字节缓存对象- Parameters:
sync- 是否线程安全
-
Buffer
public Buffer(int capacity, boolean sync)按指定的大小构造一个字节缓存对象- Parameters:
capacity- 初始容量sync- 是否线程安全
-
Buffer
public Buffer(byte[] data)
按指定的字节数组构造一个字节缓存对象- Parameters:
data- 初始化数组
-
Buffer
public Buffer(byte[] data, boolean sync)按指定的字节数组构造一个字节缓存对象- Parameters:
data- 初始化数组sync- 是否线程安全
-
Buffer
public Buffer(byte[] data, int index, int length, boolean sync)按指定的字节数组构造一个字节缓存对象- Parameters:
data- 初始化数组index- 读索引length- 写索引sync- 是否线程安全
-
-
Method Detail
-
capacity
public void capacity(int len)
设置字节缓存的容积,只能扩大容积- Parameters:
len- 长度
-
top
public int top()
得到写字节的偏移量- Returns:
- 偏移
-
top
public void top(int top)
设置写字节的偏移量- Parameters:
top- 偏移
-
offset
public int offset()
得到读数据的偏移量- Returns:
- 偏移
-
offset
public void offset(int offset)
设置读数据的偏移量- Parameters:
offset- 偏移
-
remaining
public int remaining()
剩余多少可读字节==写偏移量-读偏移量得差值- Returns:
- 剩余字节
-
hasRemaining
public boolean hasRemaining()
是否还有任何一个可读字节- Returns:
- 是否可读
-
length
public int length()
得到字节数组的长度- Returns:
- 长度
-
read
public byte[] read(int len)
按当前偏移位置读入指定的长度的字节数组- Parameters:
len- 长度- Returns:
- 字节数组
-
read
public byte[] read(byte[] data)
按当前偏移位置读入指定的字节数组- Parameters:
data- 指定的字节数组- Returns:
- 字节数组
-
read
public byte[] read(byte[] data, int pos, int len)按当前偏移位置读入指定的字节数组- Parameters:
data- 指定的字节数组pos- 指定的字节数组的起始位置len- 读入的长度- Returns:
- 字节数组
-
readBoolean
public boolean readBoolean()
读出一个布尔值- Returns:
- boolean
-
readByte
public byte readByte()
读出一个字节- Returns:
- 字节
-
readChar
public char readChar()
读出一个字符- Returns:
- 字符
-
readShort
public short readShort()
读出一个短整型数值- Returns:
- short
-
readInt
public int readInt()
读出一个整型数值- Returns:
- int
-
readFloat
public float readFloat()
读出一个浮点数值- Returns:
- float
-
readLong
public long readLong()
读出一个长整型数值- Returns:
- long
-
readDouble
public double readDouble()
读出一个双浮点数值- Returns:
- double
-
readString
public java.lang.String readString(int len)
读出一个指定长度的字符串- Parameters:
len- 长度- Returns:
- String
-
readString
public java.lang.String readString()
读出一个字符串,长度不超过65534- Returns:
- String
-
write
public byte[] write(byte[] data)
写入指定字节数组- Parameters:
data- 指定的字节数组- Returns:
- 字节数组
-
write
public byte[] write(byte[] data, int pos, int len)写入指定字节数组- Parameters:
data- 指定的字节数组pos- 指定的字节数组的起始位置len- 写入的长度- Returns:
- 字节数组
-
writeBoolean
public void writeBoolean(boolean b)
写入一个布尔值- Parameters:
b- 布尔
-
writeByte
public void writeByte(byte b)
写入一个字节- Parameters:
b- 字节
-
writeChar
public void writeChar(char c)
写入一个字符- Parameters:
c- 字符
-
writeShort
public void writeShort(int i)
写入一个短整型数值- Parameters:
i- int
-
writeShort
public void writeShort(short s)
写入一个短整型数值- Parameters:
s- short
-
writeShort
public void writeShort(short s, int pos)在指定位置写入一个短整型数值,length不变- Parameters:
s- shortpos- 位置
-
writeInt
public void writeInt(int i)
写入一个整型数值- Parameters:
i- int
-
writeInt
public void writeInt(int i, int pos)在指定位置写入一个整型数值,length不变- Parameters:
i- intpos- 位置
-
writeFloat
public void writeFloat(float f)
写入一个浮点数值- Parameters:
f- float
-
writeLong
public void writeLong(long l)
写入一个长整型数值- Parameters:
l- long
-
writeLong
public void writeLong(long l, int pos)写入一个长整型数值- Parameters:
l- longpos- 位置
-
writeDouble
public void writeDouble(double d)
写入一个双浮点数值- Parameters:
d- double
-
writeString
public void writeString(java.lang.String s)
写入一个字符串,可以为null- Parameters:
s- 字符串
-
compact
public void compact()
压缩缓冲区 抛弃以读数据 并把容量截取到写坐标
-
clear
public void clear()
清除字节缓存对象
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-