From 1554768fe315e6f56652e750db0937a15aa192f6 Mon Sep 17 00:00:00 2001 From: Sergey Tselovalnikov Date: Wed, 15 Jul 2020 14:15:57 +1000 Subject: [PATCH] Avoid large allocations of tmp buffers in buferutil Signed-off-by: Sergey Tselovalnikov --- .../src/main/java/org/eclipse/jetty/util/BufferUtil.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/BufferUtil.java b/jetty-util/src/main/java/org/eclipse/jetty/util/BufferUtil.java index 3d3b4258238b..2b8f0f9bd97f 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/BufferUtil.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/BufferUtil.java @@ -553,10 +553,12 @@ public static void writeTo(ByteBuffer buffer, OutputStream out) throws IOExcepti } else { - byte[] bytes = new byte[TEMP_BUFFER_SIZE]; + byte[] bytes = null; while (buffer.hasRemaining()) { int byteCountToWrite = Math.min(buffer.remaining(), TEMP_BUFFER_SIZE); + if (bytes == null) + bytes = new byte[byteCountToWrite]; buffer.get(bytes, 0, byteCountToWrite); out.write(bytes, 0, byteCountToWrite); }