474068 - Update WebSocket Extension for permessage-deflate draft-22
+ Copying inflated byte buffers + Simplifying Accumulator of buffer/chunks + Removing references to frame compression extensions
This commit is contained in:
parent
aac9568a30
commit
ffcedde60a
|
@ -27,7 +27,7 @@ import org.eclipse.jetty.websocket.api.MessageTooLargeException;
|
|||
|
||||
public class ByteAccumulator
|
||||
{
|
||||
private final List<Chunk> chunks = new ArrayList<>();
|
||||
private final List<byte[]> 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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
Loading…
Reference in New Issue