if (request.getMaxSize() <= 0) {
return new BooleanCommand(HttpStatus.BadRequest, "Bad request,invalid max size:" + request.getMaxSize(),
request.getOpaque());
}
try {
final MessageSet set =
store.slice(request.getOffset(),
Math.min(this.metaConfig.getMaxTransferSize(), request.getMaxSize()));
ConsumerMessageFilter filter = this.consumerFilterManager.findFilter(topic, group);
if (set != null) {
if (zeroCopy && filter == null) {
set.write(request, ctx);
return null;
}
else {
// refer to the code of line 440 in MessageStore
// create two copies of byte array including the byteBuffer
// and new bytes
// this may not a good use case of Buffer
final ByteBuffer byteBuffer =
ByteBuffer.allocate(Math.min(this.metaConfig.getMaxTransferSize(), request.getMaxSize()));
set.read(byteBuffer);
byte[] bytes = this.getBytesFromBuffer(byteBuffer);
// If filter is not null,we filter the messages by it.
if (filter != null) {
MessageIterator it = new MessageIterator(topic, bytes);
// reuse the buffer.