@Override public int write(final ByteBuffer src) throws IOException { if (log.isDebugEnabled()) { log.debug(exchangeId + ": produce request data, len " + src.remaining() + " bytes"); } return channel.write(src); }
@Override public int write(final ByteBuffer src) throws IOException { final ByteBuffer dup = src.duplicate(); final int writtenBytes = channel.write(src); if (writtenBytes > 0) { dup.limit(dup.position() + writtenBytes); digester.update(dup); } return writtenBytes; }
@Override public int write(final ByteBuffer src) throws IOException { final ByteBuffer dup = src.duplicate(); final int writtenBytes = channel.write(src); if (writtenBytes > 0) { dup.limit(dup.position() + writtenBytes); digester.update(dup); } return writtenBytes; }
@Override public final void produce(final DataStreamChannel channel) throws IOException { if (bytebuf.hasRemaining()) { channel.write(bytebuf); } if (!bytebuf.hasRemaining()) { channel.endStream(); } }
@Override public final void produce(final DataStreamChannel channel) throws IOException { if (bytebuf.hasRemaining()) { channel.write(bytebuf); } if (!bytebuf.hasRemaining()) { channel.endStream(); } }
@Override public int write(final ByteBuffer src) throws IOException { Args.notNull(src, "Buffer"); final int chunk = src.remaining(); if (chunk == 0) { return 0; } if (bytebuf.remaining() >= chunk) { bytebuf.put(src); return chunk; } int totalBytesWritten = 0; if (!bytebuf.hasRemaining() || bytebuf.position() >= fragmentSizeHint) { bytebuf.flip(); final int bytesWritten = channel.write(bytebuf); bytebuf.compact(); totalBytesWritten += bytesWritten; } if (bytebuf.position() == 0) { final int bytesWritten = channel.write(src); totalBytesWritten += bytesWritten; } return totalBytesWritten; }
@Override public void produce(final DataStreamChannel channel) throws IOException { @SuppressWarnings("resource") RandomAccessFile accessFile = accessFileRef.get(); if (accessFile == null) { accessFile = new RandomAccessFile(file, "r"); Asserts.check(accessFileRef.getAndSet(accessFile) == null, "Illegal producer state"); } if (!eof) { final int bytesRead = accessFile.getChannel().read(byteBuffer); if (bytesRead < 0) { eof = true; } } if (byteBuffer.position() > 0) { byteBuffer.flip(); channel.write(byteBuffer); byteBuffer.compact(); } if (eof && byteBuffer.position() == 0) { channel.endStream(); releaseResources(); } }
@Override public void produce(final DataStreamChannel channel) throws IOException { @SuppressWarnings("resource") RandomAccessFile accessFile = accessFileRef.get(); if (accessFile == null) { accessFile = new RandomAccessFile(file, "r"); Asserts.check(accessFileRef.getAndSet(accessFile) == null, "Illegal producer state"); } if (!eof) { final int bytesRead = accessFile.getChannel().read(byteBuffer); if (bytesRead < 0) { eof = true; } } if (byteBuffer.position() > 0) { byteBuffer.flip(); channel.write(byteBuffer); byteBuffer.compact(); } if (eof && byteBuffer.position() == 0) { channel.endStream(); releaseResources(); } }
channel.write(bytebuf); bytebuf.compact();
public void flush(final DataStreamChannel channel) throws IOException { lock.lock(); try { dataStreamChannel = channel; hasCapacity = true; setOutputMode(); if (buffer().hasRemaining()) { dataStreamChannel.write(buffer()); } if (!buffer().hasRemaining() && endStream) { dataStreamChannel.endStream(); } condition.signalAll(); } finally { lock.unlock(); } }
while (buffers.size() > 0) { final ByteBuffer nextBuffer = buffers.remove(); channel.write(nextBuffer); if (nextBuffer.remaining() > 0) { buffers.push(nextBuffer);
public void flush(final DataStreamChannel channel) throws IOException { lock.lock(); try { dataStreamChannel = channel; hasCapacity = true; setOutputMode(); if (buffer().hasRemaining()) { dataStreamChannel.write(buffer()); } if (!buffer().hasRemaining() && endStream) { dataStreamChannel.endStream(); } condition.signalAll(); } finally { lock.unlock(); } }
while (buffers.size() > 0) { final ByteBuffer nextBuffer = buffers.remove(); channel.write(nextBuffer); if (nextBuffer.remaining() > 0) { buffers.push(nextBuffer);
@Override public final void produce(final DataStreamChannel channel) throws IOException { if (state.compareTo(State.ACTIVE) == 0) { produceData(charDataStream); } if (state.compareTo(State.ACTIVE) > 0 || !bytebuf.hasRemaining() || bytebuf.position() >= fragmentSizeHint) { bytebuf.flip(); channel.write(bytebuf); bytebuf.compact(); } if (state.compareTo(State.FLUSHING) == 0) { final CoderResult result = charsetEncoder.encode(EMPTY, bytebuf, true); if (result.isError()) { result.throwException(); } else if (result.isUnderflow()) { final CoderResult result2 = charsetEncoder.flush(bytebuf); if (result2.isError()) { result.throwException(); } else if (result2.isUnderflow()) { state = State.END_STREAM; } } } if (bytebuf.position() == 0 && state.compareTo(State.END_STREAM) == 0) { channel.endStream(); } }
@Override public void write(final byte[] b, final int off, final int len) throws IOException { final ByteBuffer src = ByteBuffer.wrap(b, off, len); lock.lock(); try { ensureNotAborted(); setInputMode(); while (src.hasRemaining()) { // always buffer small chunks if (src.remaining() < 1024 && buffer().remaining() > src.remaining()) { buffer().put(src); } else { if (buffer().position() > 0 || dataStreamChannel == null) { waitFlush(); } if (buffer().position() == 0 && dataStreamChannel != null) { final int bytesWritten = dataStreamChannel.write(src); if (bytesWritten == 0) { hasCapacity = false; waitFlush(); } } } } } finally { lock.unlock(); } }
@Override public void write(final byte[] b, final int off, final int len) throws IOException { final ByteBuffer src = ByteBuffer.wrap(b, off, len); lock.lock(); try { ensureNotAborted(); setInputMode(); while (src.hasRemaining()) { // always buffer small chunks if (src.remaining() < 1024 && buffer().remaining() > src.remaining()) { buffer().put(src); } else { if (buffer().position() > 0 || dataStreamChannel == null) { waitFlush(); } if (buffer().position() == 0 && dataStreamChannel != null) { final int bytesWritten = dataStreamChannel.write(src); if (bytesWritten == 0) { hasCapacity = false; waitFlush(); } } } } } finally { lock.unlock(); } }