@Override public int available() throws IOException { return delegate.available(); }
protected void validateRequest(StreamInput stream, long requestId, String action) throws IOException { final int nextByte = stream.read(); // calling read() is useful to make sure the message is fully read, even if there some kind of EOS marker if (nextByte != -1) { throw new IllegalStateException("Message not fully read (request) for requestId [" + requestId + "], action [" + action + "], available [" + stream.available() + "]; resetting"); } }
void handleHandshake(Version version, Set<String> features, TcpChannel channel, long requestId, StreamInput stream) throws IOException { // Must read the handshake request to exhaust the stream HandshakeRequest handshakeRequest = new HandshakeRequest(stream); final int nextByte = stream.read(); if (nextByte != -1) { throw new IllegalStateException("Handshake request not fully read for requestId [" + requestId + "], action [" + TransportHandshaker.HANDSHAKE_ACTION_NAME + "], available [" + stream.available() + "]; resetting"); } HandshakeResponse response = new HandshakeResponse(this.version); handshakeResponseSender.sendResponse(version, features, channel, response, requestId); }
@Override public int available() throws IOException { return in.available(); }
@Override public int available() throws IOException { return delegate.available(); }
@Override public int available() throws IOException { return delegate.available(); }
@Override public int available() throws IOException { return delegate.available(); }
@Override public int available() throws IOException { return delegate.available(); }
byte status = streamIn.readByte(); Version version = Version.fromId(streamIn.readInt()); if (TransportStatus.isCompress(status) && hasMessageBytesToRead && streamIn.available() > 0) { Compressor compressor; try {
protected void validateRequest(StreamInput stream, long requestId, String action) throws IOException { final int nextByte = stream.read(); // calling read() is useful to make sure the message is fully read, even if there some kind of EOS marker if (nextByte != -1) { throw new IllegalStateException("Message not fully read (request) for requestId [" + requestId + "], action [" + action + "], available [" + stream.available() + "]; resetting"); } }
protected void validateRequest(StreamInput stream, long requestId, String action) throws IOException { final int nextByte = stream.read(); // calling read() is useful to make sure the message is fully read, even if there some kind of EOS marker if (nextByte != -1) { throw new IllegalStateException("Message not fully read (request) for requestId [" + requestId + "], action [" + action + "], available [" + stream.available() + "]; resetting"); } }
public void testStreamInputBulkReadWithOffset() throws IOException { final int length = randomIntBetween(10, scaledRandomIntBetween(PAGE_SIZE * 2, PAGE_SIZE * 20)); BytesReference pbr = newBytesReference(length); StreamInput si = pbr.streamInput(); assertNotNull(si); // read a bunch of single bytes one by one int offset = randomIntBetween(1, length / 2); for (int i = 0; i < offset; i++) { assertEquals(si.available(), length - i); assertEquals(pbr.get(i), si.readByte()); } // now do NOT reset the stream - keep the stream's offset! // buffer to compare remaining bytes against bulk read byte[] pbrBytesWithOffset = Arrays.copyOfRange(BytesReference.toBytes(pbr), offset, length); // randomized target buffer to ensure no stale slots byte[] targetBytes = new byte[pbrBytesWithOffset.length]; random().nextBytes(targetBytes); // bulk-read all si.readFully(targetBytes); assertArrayEquals(pbrBytesWithOffset, targetBytes); assertEquals(si.available(), 0); }
public void testStreamInputMarkAndReset() throws IOException { int length = randomIntBetween(10, scaledRandomIntBetween(PAGE_SIZE * 2, PAGE_SIZE * 20)); BytesReference pbr = newBytesReference(length); StreamInput si = pbr.streamInput(); assertNotNull(si); StreamInput wrap = StreamInput.wrap(BytesReference.toBytes(pbr)); while(wrap.available() > 0) { if (rarely()) { wrap.mark(Integer.MAX_VALUE); si.mark(Integer.MAX_VALUE); } else if (rarely()) { wrap.reset(); si.reset(); } assertEquals(si.readByte(), wrap.readByte()); assertEquals(si.available(), wrap.available()); } }
BytesReference slice = pbr.slice(sliceOffset, sliceLength); StreamInput sliceInput = slice.streamInput(); assertEquals(sliceInput.available(), sliceLength); assertEquals(slice.get(1), sliceInput.readByte()); assertEquals(slice.get(2), sliceInput.readByte()); assertEquals(sliceInput.available(), sliceLength - 3); assertEquals(sliceInput.available(), sliceLength); assertEquals(sliceInput.available(), 0); assertEquals(sliceInput.available(), sliceLength); byte[] buffer = new byte[sliceLength + scaledRandomIntBetween(1, 100)]; int offset = scaledRandomIntBetween(0, Math.max(1, buffer.length - sliceLength - 1)); int read = sliceInput.read(buffer, offset, sliceLength / 2); assertEquals(sliceInput.available(), sliceLength - read); sliceInput.read(buffer, offset + read, sliceLength - read); assertArrayEquals(sliceBytes, Arrays.copyOfRange(buffer, offset, offset + sliceLength)); assertEquals(sliceInput.available(), 0);
byte status = streamIn.readByte(); Version version = Version.fromId(streamIn.readInt()); if (TransportStatus.isCompress(status) && hasMessageBytesToRead && streamIn.available() > 0) { Compressor compressor; try {
byte status = streamIn.readByte(); Version version = Version.fromId(streamIn.readInt()); if (TransportStatus.isCompress(status) && hasMessageBytesToRead && streamIn.available() > 0) { Compressor compressor; try {
assertThat("Stream should be fully read with version [" + version + "] for streamable [" + streamable + "]", input.available(), equalTo(0)); BytesReference newBytes = serialize(version, streamable);