Refine search
@Override public int setBytes(int index, ScatteringByteChannel in, int length) throws IOException { ensureAccessible(); ByteBuffer tmpBuf = internalNioBuffer(); tmpBuf.clear().position(index).limit(index + length); try { return in.read(tmpNioBuf); } catch (ClosedChannelException ignored) { return -1; } }
public int setBytes(int index, ScatteringByteChannel in, int length) throws IOException { ByteBuffer slice = (ByteBuffer) buffer.duplicate().limit(index + length).position(index); int readBytes = 0; while (readBytes < length) { int localReadBytes; try { localReadBytes = in.read(slice); } catch (ClosedChannelException e) { localReadBytes = -1; } if (localReadBytes < 0) { if (readBytes == 0) { return -1; } else { return readBytes; } } if (localReadBytes == 0) { break; } readBytes += localReadBytes; } return readBytes; }
public int setBytes(int index, ScatteringByteChannel in, int length) throws IOException { ByteBuffer buf = ByteBuffer.wrap(array, index, length); int readBytes = 0; do { int localReadBytes; try { localReadBytes = in.read(buf); } catch (ClosedChannelException e) { localReadBytes = -1; } if (localReadBytes < 0) { if (readBytes == 0) { return -1; } else { break; } } else if (localReadBytes == 0) { break; } readBytes += localReadBytes; } while (readBytes < length); return readBytes; }
@Override protected void close(ScatteringByteChannel input) throws IOException { input.close(); }
@Override public Void call() throws Exception { _countDownLatch.await(); while (_scatteringByteChannel.isOpen()) { handleReading(_scatteringByteChannel, _channelContext); } return null; }
public int setBytes(int index, ScatteringByteChannel in, int length) throws IOException { ByteBuffer buf = ByteBuffer.wrap(array, index, length); int readBytes = 0; do { int localReadBytes; try { localReadBytes = in.read(buf); } catch (ClosedChannelException e) { localReadBytes = -1; } if (localReadBytes < 0) { if (readBytes == 0) { return -1; } else { break; } } else if (localReadBytes == 0) { break; } readBytes += localReadBytes; } while (readBytes < length); return readBytes; }
@Override public void stop() { try { super.stop(); in.close(); in = null; out = null; started = false; } catch (IOException ex) { throw new IllegalArgumentException(ex); } }
@Override public int setBytes(int index, ScatteringByteChannel in, int length) throws IOException { ensureAccessible(); ByteBuffer tmpBuf = internalNioBuffer(); tmpBuf.clear().position(index).limit(index + length); try { return in.read(tmpBuf); } catch (ClosedChannelException ignored) { return -1; } }
public int setBytes(int index, ScatteringByteChannel in, int length) throws IOException { ByteBuffer buf = ByteBuffer.wrap(array, index, length); int readBytes = 0; do { int localReadBytes; try { localReadBytes = in.read(buf); } catch (ClosedChannelException e) { localReadBytes = -1; } if (localReadBytes < 0) { if (readBytes == 0) { return -1; } else { break; } } if (localReadBytes == 0) { break; } readBytes += localReadBytes; } while (readBytes < length); return readBytes; }
@Override public final int setBytes(int index, ScatteringByteChannel in, int length) throws IOException { checkIndex(index, length); index = idx(index); try { return in.read((ByteBuffer) internalNioBuffer().clear().position(index).limit(index + length)); } catch (ClosedChannelException ignored) { return -1; } }
/** * Simple utility method to execute a blocking read on a scattering byte channel. This method blocks until the * channel is readable, and then the message is read. * * @param channel the channel to read from * @param buffers the buffers into which bytes are to be transferred * @param offs the first buffer to use * @param len the number of buffers to use * @param <C> the channel type * @return the number of bytes read * @throws IOException if an I/O exception occurs * @since 1.2 */ public static <C extends ScatteringByteChannel & SuspendableReadChannel> long readBlocking(C channel, ByteBuffer[] buffers, int offs, int len) throws IOException { long res; while ((res = channel.read(buffers, offs, len)) == 0) { channel.awaitReadable(); } return res; }
@Override public int setBytes(int index, ScatteringByteChannel in, int length) throws IOException { ensureAccessible(); ByteBuffer tmpBuf = internalNioBuffer(); tmpBuf.clear().position(index).limit(index + length); try { return in.read(tmpBuf); } catch (ClosedChannelException ignored) { return -1; } }
/** * Simple utility method to execute a blocking read on a scattering byte channel with a timeout. This method blocks until the * channel is readable, and then the message is read. * * @param channel the channel to read from * @param buffers the buffers into which bytes are to be transferred * @param offs the first buffer to use * @param len the number of buffers to use * @param time the amount of time to wait * @param unit the unit of time to wait * @param <C> the channel type * @return the number of bytes read * @throws IOException if an I/O exception occurs * @since 1.2 */ public static <C extends ScatteringByteChannel & SuspendableReadChannel> long readBlocking(C channel, ByteBuffer[] buffers, int offs, int len, long time, TimeUnit unit) throws IOException { long res = channel.read(buffers, offs, len); if (res == 0L && Buffers.hasRemaining(buffers, offs, len)) { channel.awaitReadable(time, unit); return channel.read(buffers, offs, len); } else { return res; } }
@Override public int setBytes(int index, ScatteringByteChannel in, int length) throws IOException { checkIndex(index, length); ByteBuffer tmpBuf = internalNioBuffer(); index = idx(index); tmpBuf.clear().position(index).limit(index + length); try { return in.read(tmpBuf); } catch (ClosedChannelException ignored) { return -1; } }
checkIndex(index, length); if (length == 0) { return in.read(EMPTY_NIO_BUFFER);
@Override public int setBytes(int index, ScatteringByteChannel in, int length) throws IOException { checkIndex(index, length); ByteBuffer tmpBuf = internalNioBuffer(); index = idx(index); tmpBuf.clear().position(index).limit(index + length); try { return in.read(tmpBuf); } catch (ClosedChannelException ignored) { return -1; } }
checkIndex(index, length); if (length == 0) { return in.read(EMPTY_NIO_BUFFER);
@Override public int setBytes(int index, ScatteringByteChannel in, int length) throws IOException { ensureAccessible(); ByteBuffer tmpBuf = internalNioBuffer(); tmpBuf.clear().position(index).limit(index + length); try { return in.read(tmpNioBuf); } catch (ClosedChannelException ignored) { return -1; } }