ByteBufToBytes.java
1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package com.peony.netty.util;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
public class ByteBufToBytes {
private ByteBuf temp;
private boolean end = true;
public ByteBufToBytes(int length) {
temp = Unpooled.buffer(length);
}
public void reading(ByteBuf datas) {
datas.readBytes(temp, datas.readableBytes());
if (this.temp.writableBytes() != 0) {
end = false;
} else {
end = true;
}
}
public boolean isEnd() {
return end;
}
public byte[] readFull() {
if (end) {
byte[] contentByte = new byte[this.temp.readableBytes()];
this.temp.readBytes(contentByte);
this.temp.release();
return contentByte;
} else {
return null;
}
}
public byte[] read(ByteBuf datas) {
byte[] bytes = new byte[datas.readableBytes()];
datas.readBytes(bytes);
return bytes;
}
}