Cleanup around FrameParser.copyBuffer()
This commit is contained in:
parent
dcfa524211
commit
8bab5beb2b
|
@ -54,11 +54,23 @@ public abstract class FrameParser<T extends BaseFrame>
|
|||
this.settings = settings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy the bytes from one buffer to the other, demasking the content if necessary.
|
||||
*
|
||||
* @param src
|
||||
* the source {@link ByteBuffer}
|
||||
* @param dest
|
||||
* the destination {@link ByteBuffer}
|
||||
* @param length
|
||||
* the length of bytes to worry about
|
||||
* @return the number of bytes copied
|
||||
*/
|
||||
protected int copyBuffer(ByteBuffer src, ByteBuffer dest, int length)
|
||||
{
|
||||
int amt = Math.min(length,src.remaining());
|
||||
if (getFrame().isMasked())
|
||||
{
|
||||
// Demask the content
|
||||
byte mask[] = getFrame().getMask();
|
||||
for (int i = 0; i < amt; i++)
|
||||
{
|
||||
|
@ -67,6 +79,7 @@ public abstract class FrameParser<T extends BaseFrame>
|
|||
}
|
||||
else
|
||||
{
|
||||
// Copy the content as-is
|
||||
byte b[] = new byte[amt];
|
||||
src.get(b,0,amt);
|
||||
dest.put(b,0,amt);
|
||||
|
|
|
@ -38,7 +38,8 @@ public class PingPayloadParser extends FrameParser<PingFrame>
|
|||
payload = ByteBuffer.allocate(payloadLength);
|
||||
}
|
||||
|
||||
copyBuffer(buffer,payload,payloadLength);
|
||||
copyBuffer(buffer,payload,payload.remaining());
|
||||
|
||||
if (payload.position() >= payloadLength)
|
||||
{
|
||||
frame.setPayload(payload);
|
||||
|
|
|
@ -35,7 +35,7 @@ public class TextPayloadParser extends FrameParser<TextFrame>
|
|||
payload = ByteBuffer.allocate(payloadLength);
|
||||
}
|
||||
|
||||
copyBuffer(buffer,payload,payloadLength);
|
||||
copyBuffer(buffer,payload,payload.remaining());
|
||||
|
||||
if (payload.position() >= payloadLength)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue