byte[] buffer = new byte[100];
int index = 0;
public void recordByte(Byte b) {
index = (index + 1) % 100;
buffer[index] = b;
}
public void printLastBytes() {
for(int i = index; i < index + 100; i++) {
System.out.print(buffer[i % 100]);
}
}
可以使用ByteBuffer
重写
private static final int SIZE = 100;
private final byte[] result = new byte[SIZE];
ByteBuffer buffer = ByteBuffer.allocate(SIZE);
@Override
public void record(byte b) {
buffer.put(b);
}
@Override
public String print() {
}