Class AbstractContentEncoder
- java.lang.Object
-
- org.apache.hc.core5.http.impl.nio.AbstractContentEncoder
-
- All Implemented Interfaces:
ContentEncoder
- Direct Known Subclasses:
ChunkEncoder,IdentityEncoder,LengthDelimitedEncoder
public abstract class AbstractContentEncoder extends java.lang.Object implements ContentEncoder
AbstractContentEncoderthat serves as a base for all content encoder implementations.- Since:
- 4.0
-
-
Field Summary
Fields Modifier and Type Field Description (package private) SessionOutputBufferbuffer(package private) java.nio.channels.WritableByteChannelchannel(package private) booleancompleted(package private) BasicHttpTransportMetricsmetrics
-
Constructor Summary
Constructors Constructor Description AbstractContentEncoder(java.nio.channels.WritableByteChannel channel, SessionOutputBuffer buffer, BasicHttpTransportMetrics metrics)Creates an instance of this class.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidassertNotCompleted()protected SessionOutputBufferbuffer()protected java.nio.channels.WritableByteChannelchannel()voidcomplete()voidcomplete(java.util.List<? extends Header> trailers)Terminates the content stream.private intdoWriteChunk(java.nio.ByteBuffer src, boolean direct)private intdoWriteChunk(java.nio.ByteBuffer src, int chunk, boolean direct)protected intflushToChannel()Flushes content of the session buffer to the channel and updates transport metrics.booleanisCompleted()Returnstrueif the entity has been transferred in its entirety.protected BasicHttpTransportMetricsmetrics()protected intwriteToBuffer(java.nio.ByteBuffer src, int limit)Transfers content of the source to the buffer and updates transport metrics.protected intwriteToChannel(java.nio.ByteBuffer src)Flushes content of the given buffer to the channel and updates transport metrics.protected intwriteToChannel(java.nio.ByteBuffer src, int limit)Transfers content of the source to the channel and updates transport metrics.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.hc.core5.http.nio.ContentEncoder
write
-
-
-
-
Field Detail
-
channel
final java.nio.channels.WritableByteChannel channel
-
buffer
final SessionOutputBuffer buffer
-
metrics
final BasicHttpTransportMetrics metrics
-
completed
boolean completed
-
-
Constructor Detail
-
AbstractContentEncoder
public AbstractContentEncoder(java.nio.channels.WritableByteChannel channel, SessionOutputBuffer buffer, BasicHttpTransportMetrics metrics)Creates an instance of this class.- Parameters:
channel- the destination channel.buffer- the session output buffer that can be used to store session data for intermediate processing.metrics- Transport metrics of the underlying HTTP transport.
-
-
Method Detail
-
channel
protected java.nio.channels.WritableByteChannel channel()
-
buffer
protected SessionOutputBuffer buffer()
-
metrics
protected BasicHttpTransportMetrics metrics()
-
isCompleted
public boolean isCompleted()
Description copied from interface:ContentEncoderReturnstrueif the entity has been transferred in its entirety.- Specified by:
isCompletedin interfaceContentEncoder- Returns:
trueif all the content has been produced,falseotherwise.
-
complete
public void complete(java.util.List<? extends Header> trailers) throws java.io.IOException
Description copied from interface:ContentEncoderTerminates the content stream.- Specified by:
completein interfaceContentEncoder- Throws:
java.io.IOException- if I/O error occurs while writing content
-
complete
public final void complete() throws java.io.IOException- Throws:
java.io.IOException
-
assertNotCompleted
protected void assertNotCompleted()
-
flushToChannel
protected int flushToChannel() throws java.io.IOExceptionFlushes content of the session buffer to the channel and updates transport metrics.- Returns:
- number of bytes written to the channel.
- Throws:
java.io.IOException- Since:
- 4.3
-
writeToChannel
protected int writeToChannel(java.nio.ByteBuffer src) throws java.io.IOExceptionFlushes content of the given buffer to the channel and updates transport metrics.- Returns:
- number of bytes written to the channel.
- Throws:
java.io.IOException- Since:
- 4.3
-
writeToChannel
protected int writeToChannel(java.nio.ByteBuffer src, int limit) throws java.io.IOExceptionTransfers content of the source to the channel and updates transport metrics.- Parameters:
src- source.limit- max number of bytes to transfer.- Returns:
- number of bytes transferred.
- Throws:
java.io.IOException- Since:
- 4.3
-
writeToBuffer
protected int writeToBuffer(java.nio.ByteBuffer src, int limit) throws java.io.IOExceptionTransfers content of the source to the buffer and updates transport metrics.- Parameters:
src- source.limit- max number of bytes to transfer.- Returns:
- number of bytes transferred.
- Throws:
java.io.IOException- Since:
- 4.3
-
doWriteChunk
private int doWriteChunk(java.nio.ByteBuffer src, int chunk, boolean direct) throws java.io.IOException- Throws:
java.io.IOException
-
doWriteChunk
private int doWriteChunk(java.nio.ByteBuffer src, boolean direct) throws java.io.IOException- Throws:
java.io.IOException
-
-