Improve ByteBuffer copy method

This commit improves JettyWebSocketHandlerAdapter::copyByteBuffer so
that it allocates a buffer large enough for the remaining bytes
contained in the source, instead of allocating one with the capacity of
the source.

Closes gh-31857
This commit is contained in:
Arjen Poutsma 2023-12-18 15:22:48 +01:00
parent eaf7a28250
commit 24f8eac12a
1 changed files with 3 additions and 2 deletions

View File

@ -118,8 +118,9 @@ public class JettyWebSocketHandlerAdapter {
}
private static ByteBuffer copyByteBuffer(ByteBuffer src) {
ByteBuffer dest = ByteBuffer.allocate(src.capacity());
dest.put(0, src, 0, src.remaining());
ByteBuffer dest = ByteBuffer.allocate(src.remaining());
dest.put(src);
dest.flip();
return dest;
}