/** * Determine whether any of the buffers has remaining data. * * @param buffers the buffers * @return {@code true} if any of the selected buffers has remaining data */ public static boolean hasRemaining(final Buffer[] buffers) { return hasRemaining(buffers, 0, buffers.length); }
@Override public long writeFinal(ByteBuffer[] srcs, int offset, int length) throws IOException { long res = next.writeFinal(srcs, offset, length); if(!Buffers.hasRemaining(srcs, offset, length)) { if (shutdownState == 0) { shutdownState = 1; } } return res; }
/** * Writes the buffer to the conduit, and terminates writes if all the data is written * @param conduit The conduit to write to * @param srcs The data to write * @param offset The offset into the data array * @param length The number of buffers to write * @return The number of bytes written * @throws IOException */ public static long writeFinalBasic(StreamSinkConduit conduit, ByteBuffer[] srcs, int offset, int length) throws IOException { final long res = conduit.write(srcs, offset, length); if (!Buffers.hasRemaining(srcs, offset, length)) { conduit.terminateWrites(); } return res; }
/** * Simple utility method to execute a blocking write on a gathering byte channel with a timeout. The method blocks until all * the bytes are written, or until the timeout occurs. * * @param channel the channel to write on * @param buffers the data to write * @param offs the index of the first buffer to write * @param len the number of buffers to write * @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 written * @throws IOException if an I/O exception occurs * @since 1.2 */ public static <C extends GatheringByteChannel & SuspendableWriteChannel> long writeBlocking(C channel, ByteBuffer[] buffers, int offs, int len, long time, TimeUnit unit) throws IOException { long remaining = unit.toNanos(time); long now = System.nanoTime(); long t = 0; while (Buffers.hasRemaining(buffers, offs, len) && remaining > 0L) { long res = channel.write(buffers, offs, len); if (res == 0) { channel.awaitWritable(remaining, TimeUnit.NANOSECONDS); remaining -= Math.max(-now + (now = System.nanoTime()), 0L); } else { t += res; } } return t; }
/** * Writes out the data in the buffer to the channel. If all the data is written out * then the channel will have its writes shutdown. * * @param channel The channel * @param srcs The buffers * @param offset The offset into the srcs array * @param length The number buffers to write * @return The number of bytes written * @throws IOException */ public static long writeFinalBasic(StreamSinkChannel channel, ByteBuffer[] srcs, int offset, int length) throws IOException { final long res = channel.write(srcs, offset, length); if (!Buffers.hasRemaining(srcs, offset, length)) { channel.shutdownWrites(); } return res; }
@Override public long writeFinal(ByteBuffer[] srcs, int offset, int length) throws IOException { long ret = super.writeFinal(srcs, offset, length); handleWriteTimeout(ret); if(!Buffers.hasRemaining(srcs)) { if(handle != null) { handle.remove(); handle = null; } } return ret; }
/** * Simple utility method to execute a blocking write on a gathering byte channel. The method blocks until the * bytes in the buffer have been fully written. * * @param channel the channel to write on * @param buffers the data to write * @param offs the index of the first buffer to write * @param len the number of buffers to write * @param <C> the channel type * @return the number of bytes written * @throws IOException if an I/O exception occurs * @since 1.2 */ public static <C extends GatheringByteChannel & SuspendableWriteChannel> long writeBlocking(C channel, ByteBuffer[] buffers, int offs, int len) throws IOException { long t = 0; while (Buffers.hasRemaining(buffers, offs, len)) { final long res = channel.write(buffers, offs, len); if (res == 0) { channel.awaitWritable(); } else { t += res; } } return t; }
if (Buffers.hasRemaining(dsts, offs, len)) { return Buffers.copy(length, dsts, offs, len, receiveBuffer); } else {
@Override public long writeFinal(ByteBuffer[] srcs, int offset, int length) throws IOException { handleIdleTimeout(); long w = sink.writeFinal(srcs, offset, length); if(source.isReadShutdown() && !Buffers.hasRemaining(srcs, offset, length)) { if(handle != null) { handle.remove(); handle = null; } } return w; }
public boolean send(final ByteBuffer[] srcs, final int offs, final int len) throws IOException { if (len == 1) { return send(srcs[offs]); } else if (! Buffers.hasRemaining(srcs, offs, len)) { return false; } final ByteBuffer transmitBuffer = this.transmitBuffer.getResource(); final long remaining = Buffers.remaining(srcs, offs, len); final boolean longLengths = this.longLengths; final int lengthFieldSize = longLengths ? 4 : 2; if (remaining > transmitBuffer.capacity() - lengthFieldSize || ! longLengths && remaining > 65535) { throw msg.txMsgTooLarge(); } if (transmitBuffer.remaining() < lengthFieldSize + remaining && ! writeBuffer()) { return false; } if (longLengths) { transmitBuffer.putInt((int) remaining); } else { transmitBuffer.putShort((short) remaining); } Buffers.copy(transmitBuffer, srcs, offs, len); writeBuffer(); return true; }
/** * 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; } }
if (!Buffers.hasRemaining(srcs, offset, length)) { return 0L;
if (! Buffers.hasRemaining(dsts, offset, length)) { return 0L;
if (! Buffers.hasRemaining(srcs, offset, length)) { return 0L;
if (!Buffers.hasRemaining(dsts, offset, length)) { return 0L;
if (Buffers.hasRemaining(buffers)) { log.tracef("Copying message from %s into multiple buffers", receiveBuffer); Buffers.copy(buffers, offs, len, Buffers.slice(receiveBuffer, length));
/** {@inheritDoc} */ public boolean send(final ByteBuffer[] buffers, final int offs, final int len) throws IOException { synchronized (writeLock) { if (isWriteShutDown()) { throw msg.writeShutDown(); } if (!Buffers.hasRemaining(buffers, offs, len)) { return true; } final ByteBuffer transmitBuffer = this.transmitBuffer.getResource(); final long remaining = Buffers.remaining(buffers, offs, len); if (remaining > transmitBuffer.capacity() - 4L) { throw msg.txMsgTooLarge(); } log.tracef("Accepting multiple buffers into %s", transmitBuffer); if (transmitBuffer.remaining() < 4 + remaining && ! doFlushBuffer()) { log.tracef("Insufficient room to accept multiple buffers into %s", transmitBuffer); return false; } transmitBuffer.putInt((int) remaining); Buffers.copy(transmitBuffer, buffers, offs, len); log.tracef("Accepted a message into %s", transmitBuffer); return true; } }
buffered[i] = null; if (!Buffers.hasRemaining(dsts, offset, length)) { return copied;
do { synchronized (getUnwrapLock()) { if (! Buffers.hasRemaining(dsts, offset, length)) { if (unwrappedBuffer.hasRemaining() && sourceConduit.isReadResumed()) { sourceConduit.wakeupReads();
run = run && (handleHandshake(result, true) || (!isUnwrapNeeded() && Buffers.hasRemaining(srcs, offset, length))); } while (run); } catch (SSLHandshakeException e) {