/** * Scatter read. The completion handler will be called once some * data has been read or an error occurred. If a CompletionCheck * object has been provided, the completion handler will only be * called if the callHandler method returned true. If no * CompletionCheck object has been provided, the default NIO2 * behavior is used: the completion handler will be called as soon * as some data has been read, even if the read has completed inline. * * @param block is the blocking mode that will be used for this operation * @param timeout timeout duration for the read * @param unit units for the timeout duration * @param attachment an object to attach to the I/O operation that will be * used when calling the completion handler * @param check for the IO operation completion * @param handler to call when the IO is complete * @param dsts buffers * @param <A> The attachment type * @return the completion state (done, done inline, or still pending) */ public final <A> CompletionState read(BlockingMode block, long timeout, TimeUnit unit, A attachment, CompletionCheck check, CompletionHandler<Long, ? super A> handler, ByteBuffer... dsts) { if (dsts == null) { throw new IllegalArgumentException(); } return read(dsts, 0, dsts.length, block, timeout, unit, attachment, check, handler); }
private int readInternal() throws IOException { // Single byte reads for non-blocking need special handling so all // single byte reads run through this method. byte[] b = new byte[1]; int result; try { result = socketWrapper.read(listener == null, b, 0, 1); } catch (IOException ioe) { close(); throw ioe; } if (result == 0) { return -1; } else if (result == -1) { eof = true; return -1; } else { return b[0] & 0xFF; } }
@Override public boolean fill(boolean block, byte[] data, int offset, int length) throws IOException { int len = length; int pos = offset; boolean nextReadBlock = block; int thisRead = 0; while (len > 0) { thisRead = socketWrapper.read(nextReadBlock, data, pos, len); if (thisRead == 0) { if (nextReadBlock) { // Should never happen throw new IllegalStateException(); } else { return false; } } else if (thisRead == -1) { if (connectionState.get().isNewStreamAllowed()) { throw new EOFException(); } else { return false; } } else { pos += thisRead; len -= thisRead; nextReadBlock = true; } } return true; }
@Override public final int read(byte[] b, int off, int len) throws IOException { preReadChecks(); try { int result = socketWrapper.read(listener == null, b, off, len); if (result == -1) { eof = true; } return result; } catch (IOException ioe) { close(); throw ioe; } }
int nRead = wrapper.read(block, byteBuffer); byteBuffer.limit(byteBuffer.position()).reset(); if (nRead > 0) {
@Override protected boolean readFrame(boolean block, FrameType expected) throws IOException, Http2Exception { if (block) { // Only used when reading the connection preface return super.readFrame(block, expected); } handleAsyncException(); header.clear(); framePaylod.clear(); FrameCompletionHandler handler = new FrameCompletionHandler(expected, header, framePaylod); CompletionState state = socketWrapper.read(BlockingMode.NON_BLOCK, socketWrapper.getWriteTimeout(), TimeUnit.MILLISECONDS, null, handler, handler, header, framePaylod); if (state == CompletionState.ERROR || state == CompletionState.INLINE) { handleAsyncException(); return true; } else { return false; } }
int read = socketWrapper.read(false, inputBuffer); inputBuffer.limit(inputBuffer.position()).reset(); if (read < 0) {
int read = socketWrapper.read(false, inputBuffer); inputBuffer.limit(inputBuffer.position()).reset(); if (read < 0) {
int read = socketWrapper.read(false, inputBuffer); inputBuffer.limit(inputBuffer.position()).reset(); if (read < 0) {