@Override protected void produceData(final StreamChannel<ByteBuffer> channel) throws IOException { final int chunk = Math.min((int) (remaining < Integer.MAX_VALUE ? remaining : Integer.MAX_VALUE), buffer.remaining()); for (int i = 0; i < chunk; i++) { final byte b = RANGE[(int) (Math.random() * RANGE.length)]; buffer.put(b); } buffer.flip(); final int bytesWritten = channel.write(buffer); if (bytesWritten > 0) { remaining -= bytesWritten; } buffer.compact(); if (remaining <= 0) { channel.endStream(); } }
final void streamEnd(final StreamChannel<ByteBuffer> channel) throws IOException { if (state == State.ACTIVE) { state = State.FLUSHING; flush(channel); if (bytebuf.position() == 0) { state = State.END_STREAM; channel.endStream(); } } }
@Override protected void produceData(final StreamChannel<CharBuffer> channel) throws IOException { Asserts.notNull(channel, "Channel"); channel.write(content); if (!content.hasRemaining()) { channel.endStream(); } }
@Override protected void produceData(final StreamChannel<CharBuffer> channel) throws IOException { Asserts.notNull(channel, "Channel"); channel.write(content); if (!content.hasRemaining()) { channel.endStream(); } }
final void streamEnd(final StreamChannel<ByteBuffer> channel) throws IOException { if (state == State.ACTIVE) { state = State.FLUSHING; if (!bytebuf.hasRemaining()) { flush(channel); } final CoderResult result = charsetEncoder.encode(EMPTY, bytebuf, true); if (result.isError()) { result.throwException(); } final CoderResult result2 = charsetEncoder.flush(bytebuf); if (result2.isError()) { result.throwException(); } else if (result.isUnderflow()) { flush(channel); if (bytebuf.position() == 0) { state = State.END_STREAM; channel.endStream(); } } } }
@Override protected void produceData(final StreamChannel<ByteBuffer> channel) throws IOException { if (count < content.length) { channel.write(ByteBuffer.wrap(content[count])); } count++; if (count >= content.length) { channel.endStream(); } }
@Override protected void produceData(final StreamChannel<CharBuffer> channel) throws IOException { if (count < content.length) { channel.write(CharBuffer.wrap(content[count])); } count++; if (count >= content.length) { channel.endStream(); } }