org.apache.http.impl.io
Class SessionOutputBufferImpl

java.lang.Object
  extended by org.apache.http.impl.io.SessionOutputBufferImpl
All Implemented Interfaces:
BufferInfo, org.apache.http.io.SessionOutputBuffer

@NotThreadSafe
public class SessionOutputBufferImpl
extends java.lang.Object
implements org.apache.http.io.SessionOutputBuffer, BufferInfo

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

Constructor Summary
SessionOutputBufferImpl(org.apache.http.impl.io.HttpTransportMetricsImpl metrics, int buffersize)
           
SessionOutputBufferImpl(org.apache.http.impl.io.HttpTransportMetricsImpl metrics, int buffersize, int fragementSizeHint, java.nio.charset.CharsetEncoder charencoder)
          Creates new instance of SessionOutputBufferImpl.
 
Method Summary
 int available()
          Returns available space in the buffer.
 void bind(java.io.OutputStream outstream)
           
 int capacity()
          Returns total capacity of the buffer
 void flush()
           
 org.apache.http.io.HttpTransportMetrics getMetrics()
           
 boolean isBound()
           
 int length()
          Return length data stored in the buffer
 void write(byte[] b)
           
 void write(byte[] b, int off, int len)
           
 void write(int b)
           
 void writeLine(org.apache.http.util.CharArrayBuffer charbuffer)
          Writes characters from the specified char array followed by a line delimiter to this session buffer.
 void writeLine(java.lang.String s)
          Writes characters from the specified string followed by a line delimiter to this session buffer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SessionOutputBufferImpl

public SessionOutputBufferImpl(org.apache.http.impl.io.HttpTransportMetricsImpl metrics,
                               int buffersize,
                               int fragementSizeHint,
                               java.nio.charset.CharsetEncoder charencoder)
Creates new instance of SessionOutputBufferImpl.

Parameters:
metrics - HTTP transport metrics.
buffersize - buffer size. Must be a positive number.
fragementSizeHint - 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 - charencoder to be used for encoding HTTP protocol elements. If null simple type cast will be used for char to byte conversion.

SessionOutputBufferImpl

public SessionOutputBufferImpl(org.apache.http.impl.io.HttpTransportMetricsImpl metrics,
                               int buffersize)
Method Detail

bind

public void bind(java.io.OutputStream outstream)

isBound

public boolean isBound()

capacity

public int capacity()
Description copied from interface: BufferInfo
Returns total capacity of the buffer

Specified by:
capacity in interface BufferInfo
Returns:
total capacity

length

public int length()
Description copied from interface: BufferInfo
Return length data stored in the buffer

Specified by:
length in interface BufferInfo
Returns:
data length

available

public int available()
Description copied from interface: BufferInfo
Returns available space in the buffer.

Specified by:
available in interface BufferInfo
Returns:
available space.

flush

public void flush()
           throws java.io.IOException
Specified by:
flush in interface org.apache.http.io.SessionOutputBuffer
Throws:
java.io.IOException

write

public void write(byte[] b,
                  int off,
                  int len)
           throws java.io.IOException
Specified by:
write in interface org.apache.http.io.SessionOutputBuffer
Throws:
java.io.IOException

write

public void write(byte[] b)
           throws java.io.IOException
Specified by:
write in interface org.apache.http.io.SessionOutputBuffer
Throws:
java.io.IOException

write

public void write(int b)
           throws java.io.IOException
Specified by:
write in interface org.apache.http.io.SessionOutputBuffer
Throws:
java.io.IOException

writeLine

public void writeLine(java.lang.String s)
               throws java.io.IOException
Writes characters from the specified string followed by a line delimiter to this session buffer.

This method uses CR-LF as a line delimiter.

Specified by:
writeLine in interface org.apache.http.io.SessionOutputBuffer
Parameters:
s - the line.
Throws:
java.io.IOException - if an I/O error occurs.

writeLine

public void writeLine(org.apache.http.util.CharArrayBuffer charbuffer)
               throws java.io.IOException
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.

Specified by:
writeLine in interface org.apache.http.io.SessionOutputBuffer
Parameters:
charbuffer - the buffer containing chars of the line.
Throws:
java.io.IOException - if an I/O error occurs.

getMetrics

public org.apache.http.io.HttpTransportMetrics getMetrics()
Specified by:
getMetrics in interface org.apache.http.io.SessionOutputBuffer