diff --git a/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/extensions/compress/ByteAccumulator.java b/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/extensions/compress/ByteAccumulator.java index 0046b129a4b..279cdbfc90e 100644 --- a/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/extensions/compress/ByteAccumulator.java +++ b/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/extensions/compress/ByteAccumulator.java @@ -27,7 +27,7 @@ import org.eclipse.jetty.websocket.api.MessageTooLargeException; public class ByteAccumulator { - private final List chunks = new ArrayList<>(); + private final List chunks = new ArrayList<>(); private final int maxSize; private int length = 0; @@ -36,13 +36,17 @@ public class ByteAccumulator this.maxSize = maxOverallBufferSize; } - public void addChunk(byte buf[], int offset, int length) + public void copyChunk(byte buf[], int offset, int length) { if (this.length + length > maxSize) { throw new MessageTooLargeException("Frame is too large"); } - chunks.add(new Chunk(buf, offset, length)); + + byte copy[] = new byte[length - offset]; + System.arraycopy(buf,offset,copy,0,length); + + chunks.add(copy); this.length += length; } @@ -54,26 +58,16 @@ public class ByteAccumulator public void transferTo(ByteBuffer buffer) { if (buffer.remaining() < length) - throw new IllegalArgumentException(); + { + throw new IllegalArgumentException(String.format("Not enough space in ByteBuffer remaining [%d] for accumulated buffers length [%d]", + buffer.remaining(),length)); + } + int position = buffer.position(); - for (Chunk chunk : chunks) + for (byte[] chunk : chunks) { - buffer.put(chunk.buffer, chunk.offset, chunk.length); - } - BufferUtil.flipToFlush(buffer, position); - } - - private static class Chunk - { - private final byte[] buffer; - private final int offset; - private final int length; - - private Chunk(byte[] buffer, int offset, int length) - { - this.buffer = buffer; - this.offset = offset; - this.length = length; + buffer.put(chunk,0,chunk.length); } + BufferUtil.flipToFlush(buffer,position); } } diff --git a/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/extensions/compress/CompressExtension.java b/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/extensions/compress/CompressExtension.java index dae6e184c34..88bbf7ef084 100644 --- a/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/extensions/compress/CompressExtension.java +++ b/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/extensions/compress/CompressExtension.java @@ -149,7 +149,7 @@ public abstract class CompressExtension extends AbstractExtension { return; } - byte[] output = new byte[1024]; + byte[] output = new byte[1024]; // TODO: make configurable size if (inflater.needsInput() && !supplyInput(inflater, buf)) { @@ -163,22 +163,7 @@ public abstract class CompressExtension extends AbstractExtension if (read == 0) { LOG.debug("Decompress: read 0 {}",toDetail(inflater)); - if (inflater.finished() || inflater.needsDictionary()) - { - if (LOG.isDebugEnabled()) - { - LOG.debug("Decompress: finished? {}",toDetail(inflater)); - } - // We are finished ? - break; - } - else if (inflater.needsInput()) - { - if (!supplyInput(inflater, buf)) - { - break; - } - } + break; } else { @@ -187,7 +172,8 @@ public abstract class CompressExtension extends AbstractExtension { LOG.debug("Decompressed {} bytes: {}",read,toDetail(inflater)); } - accumulator.addChunk(output,0,read); + + accumulator.copyChunk(output,0,read); } } diff --git a/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/extensions/compress/package-info.java b/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/extensions/compress/package-info.java index 58efc4499f3..eb15685497b 100644 --- a/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/extensions/compress/package-info.java +++ b/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/extensions/compress/package-info.java @@ -17,7 +17,7 @@ // /** - * Jetty WebSocket Common : Frame & Message Compression Extension Implementations + * Jetty WebSocket Common : Message Compression Extension Implementations */ package org.eclipse.jetty.websocket.common.extensions.compress;