ByteBuf buffer = ... // create a buffer while (buffer.isReadable()) { byte b = buffer.readByte(); // do something with the byte }
ByteBuf buffer = ... // create a buffer while (buffer.isReadable(4)) { byte[] bytes = new byte[4]; buffer.readBytes(bytes); // do something with the bytes }
ByteBuf buffer = ... // create a buffer if (buffer.isReadable(2)) { short data = buffer.readShort(); // do something with the data }The ByteBuf class is part of the io.netty.buffer package in the Netty library.