Package org.apache.http.impl.nio.codecs
Class IdentityEncoder
- java.lang.Object
-
- org.apache.http.impl.nio.codecs.AbstractContentEncoder
-
- org.apache.http.impl.nio.codecs.IdentityEncoder
-
- All Implemented Interfaces:
ContentEncoder
,FileContentEncoder
public class IdentityEncoder extends AbstractContentEncoder implements FileContentEncoder
Content encoder that writes data without any transformation. The end of the content entity is demarcated by closing the underlying connection (EOF condition). Entities transferred using this input stream can be of unlimited length.This decoder is optimized to transfer data directly from a
FileChannel
to the underlying I/O session's channel whenever possible avoiding intermediate buffering in the session buffer.- Since:
- 4.0
-
-
Constructor Summary
Constructors Constructor Description IdentityEncoder(java.nio.channels.WritableByteChannel channel, SessionOutputBuffer buffer, HttpTransportMetricsImpl metrics)
IdentityEncoder(java.nio.channels.WritableByteChannel channel, SessionOutputBuffer buffer, HttpTransportMetricsImpl metrics, int fragementSizeHint)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String
toString()
long
transfer(java.nio.channels.FileChannel src, long position, long count)
Transfers a portion of entity content from the given file channel to the underlying network channel.int
write(java.nio.ByteBuffer src)
Writes a portion of entity content to the underlying channel.-
Methods inherited from class org.apache.http.impl.nio.codecs.AbstractContentEncoder
complete, isCompleted
-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.apache.http.nio.ContentEncoder
complete, isCompleted
-
-
-
-
Constructor Detail
-
IdentityEncoder
public IdentityEncoder(java.nio.channels.WritableByteChannel channel, SessionOutputBuffer buffer, HttpTransportMetricsImpl metrics, int fragementSizeHint)
- Parameters:
channel
- underlying channel.buffer
- session buffer.metrics
- transport metrics.fragementSizeHint
- fragment size hint defining an minimal size of a fragment that should be written out directly to the channel bypassing the session buffer. Value0
disables fragment buffering.- Since:
- 4.3
-
IdentityEncoder
public IdentityEncoder(java.nio.channels.WritableByteChannel channel, SessionOutputBuffer buffer, HttpTransportMetricsImpl metrics)
-
-
Method Detail
-
write
public int write(java.nio.ByteBuffer src) throws java.io.IOException
Description copied from interface:ContentEncoder
Writes a portion of entity content to the underlying channel.- Specified by:
write
in interfaceContentEncoder
- Parameters:
src
- The buffer from which content is to be retrieved- Returns:
- The number of bytes read, possibly zero
- Throws:
java.io.IOException
- if I/O error occurs while writing content
-
transfer
public long transfer(java.nio.channels.FileChannel src, long position, long count) throws java.io.IOException
Description copied from interface:FileContentEncoder
Transfers a portion of entity content from the given file channel to the underlying network channel.- Specified by:
transfer
in interfaceFileContentEncoder
- Parameters:
src
- the source FileChannel to transfer data from.position
- The position within the file at which the transfer is to begin; must be non-negativecount
- The maximum number of bytes to be transferred; must be non-negative- Returns:
- The number of bytes, possibly zero, that were actually transferred
- Throws:
java.io.IOException
- if some I/O error occurs.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-