Github user clebertsuconic commented on the issue:
https://github.com/apache/activemq-artemis/pull/1351
@gaohoward nice catch!
Can we do it differntly... change LargeServerMessageImpl to not reuse the
same buffer instead?
this will introduce an extra copy for regular cases.. I would rather keep
the hot path unchnaged.. and only cause the extra copy on the actualy copy.
That is...
```java
for (;;) {
byte[] bufferBytes = new byte[100 * 1024];
ByteBuffer buffer = ByteBuffer.wrap(bufferBytes);
// The buffer is reused...
// We need to make sure we clear the limits and the buffer
before reusing it
buffer.clear();
int bytesRead = file.read(buffer);
byte[] bufferToWrite;
if (bytesRead <= 0) {
break;
} else if (bytesRead == bufferBytes.length) {
bufferToWrite = bufferBytes;
} else {
bufferToWrite = new byte[bytesRead];
System.arraycopy(bufferBytes, 0, bufferToWrite, 0,
bytesRead);
}
newMessage.addBytes(bufferToWrite);
if (bytesRead < bufferBytes.length) {
break;
}
}
```
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---