@Override protected void processRemaining(ByteBuffer buffer) { b += buffer.remaining(); for (int i = 0; buffer.hasRemaining(); i += 8) { finalM ^= (buffer.get() & 0xFFL) << i; } }
/** * Flips the buffer output buffer so we can start reading bytes from it. If we are starting to * drain because there was overflow, and there aren't actually any characters to drain, then the * overflow must be due to a small output buffer. */ private void startDraining(boolean overflow) { byteBuffer.flip(); if (overflow && byteBuffer.remaining() == 0) { byteBuffer = ByteBuffer.allocate(byteBuffer.capacity() * 2); } else { draining = true; } }
/** * Create a new binary WebSocket message by wrapping an existing byte array. * @param payload a non-null payload; note that this value is not copied so care * must be taken not to modify the array. * @param offset the offset into the array where the payload starts * @param length the length of the array considered for the payload * @param isLast if the message is the last of a series of partial messages */ public BinaryMessage(byte[] payload, int offset, int length, boolean isLast) { super(ByteBuffer.wrap(payload, offset, length), isLast); }
@Override protected void process(ByteBuffer bb) { while (bb.hasRemaining()) { bb.get(); } } };
/** * Create a new ping message with an empty payload. */ public PingMessage() { super(ByteBuffer.allocate(0)); }
/** * Calculate the current buffer size. */ public int getBufferSize() { int size = 0; for (ByteBuffer buffer : this.chunks) { size = size + buffer.remaining(); } return size; }
@Override public ByteBuffer asByteBuffer(int index, int length) { checkIndex(index, length); ByteBuffer duplicate = this.byteBuffer.duplicate(); // Explicit access via Buffer base type for compatibility // with covariant return type on JDK 9's ByteBuffer... Buffer buffer = duplicate; buffer.position(index); buffer.limit(index + length); return duplicate.slice(); }
@Override public int arrayOffset() { return buffer.arrayOffset(); } }
/** Creates a new {@code CharBuffer} for buffering reads or writes. */ static CharBuffer createBuffer() { return CharBuffer.allocate(DEFAULT_BUF_SIZE); }
@Override public ByteBuffer toByteBuffer(int index, int length) { return ByteBuffer.wrap(array, index, length); } }
/** * Create a new pong message with an empty payload. */ public PongMessage() { super(ByteBuffer.allocate(0)); }
@Override public int arrayOffset() { return buffer.arrayOffset(); } }
@Override public ByteBuffer toByteBuffer(int index, int length) { return ByteBuffer.wrap(array, index, length); } }