Top Description Fields Constructors Methods
org.apache.http.impl.io

public Class SessionOutputBufferImpl

extends Object
implements SessionOutputBuffer, BufferInfo
Class Inheritance
All Implemented Interfaces
org.apache.http.io.BufferInfo, org.apache.http.io.SessionOutputBuffer
Imports
java.io.IOException, .OutputStream, java.nio.ByteBuffer, .CharBuffer, java.nio.charset.CharsetEncoder, .CoderResult, org.apache.http.io.BufferInfo, .HttpTransportMetrics, .SessionOutputBuffer, org.apache.http.protocol.HTTP, org.apache.http.util.Args, .Asserts, .ByteArrayBuffer, .CharArrayBuffer

Abstract base class for session output buffers that stream data to an arbitrary OutputStream. This class buffers small chunks of output data in an internal byte array for optimal output performance.

writeLine(CharArrayBuffer) and writeLine(String) methods of this class use CR-LF as a line delimiter.

Since
4.3

Field Summary

Modifier and TypeField and Description
private ByteBuffer
private final ByteArrayBuffer
private static final byte[]
private final CharsetEncoder
private final int
private final HttpTransportMetricsImpl
private OutputStream

Constructor Summary

AccessConstructor and Description
public
SessionOutputBufferImpl(final HttpTransportMetricsImpl
HTTP transport metrics.
metrics
,
final int
buffer size. Must be a positive number.
bufferSize
,
final int
fragment size hint defining a minimal size of a fragment that should be written out directly to the socket bypassing the session buffer. Value 0 disables fragment buffering.
fragementSizeHint
,
final CharsetEncoder
charEncoder to be used for encoding HTTP protocol elements. If null simple type cast will be used for char to byte conversion.
charEncoder
)

Creates new instance of SessionOutputBufferImpl.

public
SessionOutputBufferImpl(final HttpTransportMetricsImpl metrics, final int bufferSize)

Method Summary

Modifier and TypeMethod and Description
public int
available()

Implements org.apache.http.io.BufferInfo.available.

Returns available space in the buffer.
public void
bind(final OutputStream outStream)

public int
capacity()

Implements org.apache.http.io.BufferInfo.capacity.

Returns total capacity of the buffer
public void
flush()

Implements org.apache.http.io.SessionOutputBuffer.flush.

Flushes this session buffer and forces any buffered output bytes to be written out.
private void
private void
public HttpTransportMetrics
private void
public boolean
public int
length()

Implements org.apache.http.io.BufferInfo.length.

Return length data stored in the buffer
private void
streamWrite(final byte[] b, final int off, final int len)

public void
write(final byte[]
the data.
b
,
final int
the start offset in the data.
off
,
final int
the number of bytes to write.
len
)

Implements org.apache.http.io.SessionOutputBuffer.write.

Writes len bytes from the specified byte array starting at offset off to this session buffer.
public void
write(final byte[]
the data.
b
)

Implements org.apache.http.io.SessionOutputBuffer.write.

Writes b.length bytes from the specified byte array to this session buffer.
public void
write(final int
the byte.
b
)

Implements org.apache.http.io.SessionOutputBuffer.write.

Writes the specified byte to this session buffer.
private void
public void
writeLine(final String
the line.
s
)

Implements org.apache.http.io.SessionOutputBuffer.writeLine.

Writes characters from the specified string followed by a line delimiter to this session buffer.
public void
writeLine(final CharArrayBuffer
the buffer containing chars of the line.
charbuffer
)

Implements org.apache.http.io.SessionOutputBuffer.writeLine.

Writes characters from the specified char array followed by a line delimiter to this session buffer.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

bbufback to summary
private ByteBuffer bbuf
bufferback to summary
private final ByteArrayBuffer buffer
CRLFback to summary
private static final byte[] CRLF
encoderback to summary
private final CharsetEncoder encoder
fragementSizeHintback to summary
private final int fragementSizeHint
metricsback to summary
private final HttpTransportMetricsImpl metrics
outStreamback to summary
private OutputStream outStream

Constructor Detail

SessionOutputBufferImplback to summary
public SessionOutputBufferImpl(final HttpTransportMetricsImpl metrics, final int bufferSize, final int fragementSizeHint, final CharsetEncoder charEncoder)

Creates new instance of SessionOutputBufferImpl.

Parameters
metrics:HttpTransportMetricsImpl

HTTP transport metrics.

bufferSize:int

buffer size. Must be a positive number.

fragementSizeHint:int

fragment size hint defining a minimal size of a fragment that should be written out directly to the socket bypassing the session buffer. Value 0 disables fragment buffering.

charEncoder:CharsetEncoder

charEncoder to be used for encoding HTTP protocol elements. If null simple type cast will be used for char to byte conversion.

SessionOutputBufferImplback to summary
public SessionOutputBufferImpl(final HttpTransportMetricsImpl metrics, final int bufferSize)

Method Detail

availableback to summary
public int available()

Implements org.apache.http.io.BufferInfo.available.

Doc from org.apache.http.io.BufferInfo.available.

Returns available space in the buffer.

Returns:int

available space.

Annotations
@Override
bindback to summary
public void bind(final OutputStream outStream)
capacityback to summary
public int capacity()

Implements org.apache.http.io.BufferInfo.capacity.

Doc from org.apache.http.io.BufferInfo.capacity.

Returns total capacity of the buffer

Returns:int

total capacity

Annotations
@Override
flushback to summary
public void flush() throws IOException

Implements org.apache.http.io.SessionOutputBuffer.flush.

Doc from org.apache.http.io.SessionOutputBuffer.flush.

Flushes this session buffer and forces any buffered output bytes to be written out. The general contract of flush is that calling it is an indication that, if any bytes previously written have been buffered by the implementation of the output stream, such bytes should immediately be written to their intended destination.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs.
flushBufferback to summary
private void flushBuffer() throws IOException
flushStreamback to summary
private void flushStream() throws IOException
getMetricsback to summary
public HttpTransportMetrics getMetrics()

Implements org.apache.http.io.SessionOutputBuffer.getMetrics.

Doc from org.apache.http.io.SessionOutputBuffer.getMetrics.

Returns HttpTransportMetrics for this session buffer.

Returns:HttpTransportMetrics

transport metrics.

Annotations
@Override
handleEncodingResultback to summary
private void handleEncodingResult(final CoderResult result) throws IOException
isBoundback to summary
public boolean isBound()
lengthback to summary
public int length()

Implements org.apache.http.io.BufferInfo.length.

Doc from org.apache.http.io.BufferInfo.length.

Return length data stored in the buffer

Returns:int

data length

Annotations
@Override
streamWriteback to summary
private void streamWrite(final byte[] b, final int off, final int len) throws IOException
writeback to summary
public void write(final byte[] b, final int off, final int len) throws IOException

Implements org.apache.http.io.SessionOutputBuffer.write.

Doc from org.apache.http.io.SessionOutputBuffer.write.

Writes len bytes from the specified byte array starting at offset off to this session buffer.

If off is negative, or len is negative, or off+len is greater than the length of the array b, then an IndexOutOfBoundsException is thrown.

Parameters
b:byte[]

the data.

off:int

the start offset in the data.

len:int

the number of bytes to write.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs.
writeback to summary
public void write(final byte[] b) throws IOException

Implements org.apache.http.io.SessionOutputBuffer.write.

Doc from org.apache.http.io.SessionOutputBuffer.write.

Writes b.length bytes from the specified byte array to this session buffer.

Parameters
b:byte[]

the data.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs.
writeback to summary
public void write(final int b) throws IOException

Implements org.apache.http.io.SessionOutputBuffer.write.

Doc from org.apache.http.io.SessionOutputBuffer.write.

Writes the specified byte to this session buffer.

Parameters
b:int

the byte.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs.
writeEncodedback to summary
private void writeEncoded(final CharBuffer cbuf) throws IOException
writeLineback to summary
public void writeLine(final String s) throws IOException

Implements org.apache.http.io.SessionOutputBuffer.writeLine.

Writes characters from the specified string followed by a line delimiter to this session buffer.

This method uses CR-LF as a line delimiter.

Parameters
s:String

the line.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs.
writeLineback to summary
public void writeLine(final CharArrayBuffer charbuffer) throws IOException

Implements org.apache.http.io.SessionOutputBuffer.writeLine.

Writes characters from the specified char array followed by a line delimiter to this session buffer.

This method uses CR-LF as a line delimiter.

Parameters
charbuffer:CharArrayBuffer

the buffer containing chars of the line.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs.