Skip to content

Commit 24f8eac

Browse files
committed
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
1 parent eaf7a28 commit 24f8eac

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

spring-websocket/src/main/java/org/springframework/web/socket/adapter/jetty/JettyWebSocketHandlerAdapter.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,9 @@ public void onWebSocketFrame(Frame frame, Callback callback) {
118118
}
119119

120120
private static ByteBuffer copyByteBuffer(ByteBuffer src) {
121-
ByteBuffer dest = ByteBuffer.allocate(src.capacity());
122-
dest.put(0, src, 0, src.remaining());
121+
ByteBuffer dest = ByteBuffer.allocate(src.remaining());
122+
dest.put(src);
123+
dest.flip();
123124
return dest;
124125
}
125126

0 commit comments

Comments
 (0)