org.apache.http.nio.ContentEncoder Java Examples
The following examples show how to use
org.apache.http.nio.ContentEncoder.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CXFHttpAsyncRequestProducer.java From cxf with Apache License 2.0 | 6 votes |
public void produceContent(final ContentEncoder enc, final IOControl ioc) throws IOException { if (content != null) { if (buffer == null) { if (content.getTempFile() == null) { buffer = ByteBuffer.wrap(content.getBytes()); } else { fis = content.getInputStream(); chan = (fis instanceof FileInputStream) ? ((FileInputStream)fis).getChannel() : Channels.newChannel(fis); buffer = ByteBuffer.allocate(8 * 1024); } } int i = -1; ((Buffer)buffer).rewind(); if (buffer.hasRemaining() && chan != null) { i = chan.read(buffer); buffer.flip(); } enc.write(buffer); if (!buffer.hasRemaining() && i == -1) { enc.complete(); } } else { buf.produceContent(enc, ioc); } }
Example #2
Source File: SharedOutputBuffer.java From cxf with Apache License 2.0 | 5 votes |
public int produceContent(final ContentEncoder encoder, final IOControl ioc) throws IOException { if (this.shutdown) { return -1; } this.lock.lock(); try { this.ioctrl = ioc; setOutputMode(); int bytesWritten = 0; if (largeWrapper != null || super.hasData()) { if (!this.buffer.hasRemaining() && largeWrapper != null) { bytesWritten = encoder.write(largeWrapper); } else { bytesWritten = encoder.write(this.buffer); } if (encoder.isCompleted()) { this.endOfStream = true; } } if ((largeWrapper == null || !largeWrapper.hasRemaining()) && !super.hasData()) { // No more buffered content // If at the end of the stream, terminate if (this.endOfStream && !encoder.isCompleted()) { encoder.complete(); } if (!this.endOfStream && this.ioctrl != null) { // suspend output events this.ioctrl.suspendOutput(); } } // no need to signal if the large wrapper is present and has data remaining if (largeWrapper == null || !largeWrapper.hasRemaining()) { this.condition.signalAll(); } return bytesWritten; } finally { this.lock.unlock(); } }
Example #3
Source File: HttpAsyncRequestProducerWrapper.java From apm-agent-java with Apache License 2.0 | 4 votes |
@Override public void produceContent(ContentEncoder encoder, IOControl ioctrl) throws IOException { delegate.produceContent(encoder, ioctrl); }
Example #4
Source File: TracingHttpAsyncClientBuilder.java From brave with Apache License 2.0 | 4 votes |
@Override public void produceContent(ContentEncoder encoder, IOControl io) throws IOException { requestProducer.produceContent(encoder, io); }