HTTP Http OutputStream.
Acts as a BufferedOutputStream until setChunking() is called.
Once chunking is enabled, the raw stream is chunk encoded as per RFC2616.
Implements the following HTTP and Servlet features:
- Filters for content and transfer encodings.
- Allows output to be reset if not committed (buffer never flushed).
- Notification of significant output events for filter triggering,
header flushing, etc.
This class is not synchronized and should be synchronized
explicitly if an instance is used by multiple threads.
HttpOutputStream
public HttpOutputStream(OutputStream outputStream)
Constructor.
outputStream
- The outputStream to buffer or chunk to.
HttpOutputStream
public HttpOutputStream(OutputStream outputStream,
int bufferSize)
Constructor.
outputStream
- The outputStream to buffer or chunk to.
HttpOutputStream
public HttpOutputStream(OutputStream outputStream,
int bufferSize,
int headerReserve)
Constructor.
outputStream
- The outputStream to buffer or chunk to.
addObserver
public void addObserver(OutputObserver observer)
Add an Output Observer.
Output Observers get notified of significant events on the
output stream. Observers are called in the reverse order they
were added.
They are removed when the stream is closed.
addObserver
public void addObserver(OutputObserver observer,
Object data)
Add an Output Observer.
Output Observers get notified of significant events on the
output stream. Observers are called in the reverse order they
were added.
They are removed when the stream is closed.
observer
- The observer.data
- Data to be passed wit notify calls.
checkOutput
protected void checkOutput()
close
public void close()
throws IOException
Close the stream.
destroy
public void destroy()
flush
public void flush()
throws IOException
getBufferSize
public int getBufferSize()
Get the output buffer capacity.
- Buffer capacity in bytes.
getBufferedOutputStream
public OutputStream getBufferedOutputStream()
Get the buffered output stream.
getBytesWritten
public int getBytesWritten()
getOutputStream
public OutputStream getOutputStream()
Get the backing output stream.
A stream without filters or chunking is returned.
getWriter
public Writer getWriter(String encoding)
throws IOException
isChunking
public boolean isChunking()
Get chunking mode
isClosed
public boolean isClosed()
throws IOException
Close the stream.
isNullOutput
public boolean isNullOutput()
throws IOException
is the output Nulled?
isWritten
public boolean isWritten()
Has any data been written to the stream.
- True if write has been called.
nullOutput
public void nullOutput()
throws IOException
Null the output.
All output written is discarded until the stream is reset. Used
for HEAD requests.
outputNotify
public void outputNotify(OutputStream out,
int action,
Object ignoredData)
throws IOException
Output Notification.
Called by the internal Buffered Output and the event is passed on to
this streams observers.
- outputNotify in interface OutputObserver
prepareOutput
protected int prepareOutput(int length)
throws IOException
resetBuffer
public void resetBuffer()
throws IllegalStateException
Reset Buffered output.
If no data has been committed, the buffer output is discarded and
the filters may be reinitialized.
resetObservers
public void resetObservers()
Reset the observers.
resetStream
public void resetStream()
throws IOException,
IllegalStateException
Reset the stream.
Turn disable all filters.
setBufferSize
public void setBufferSize(int size)
throws IllegalStateException
Set the output buffer size.
Note that this is the minimal buffer size and that installed
filters may perform their own buffering and are likely to change
the size of the output. Also the pre and post reserve buffers may be
allocated within the buffer for headers and chunking.
size
- Minimum buffer size in bytes
setChunking
public void setChunking()
Set chunking mode.
setContentLength
public void setContentLength(int length)
toString
public String toString()
write
public void write(InputStream in,
int len)
throws IOException
write
public void write(b[] )
throws IOException
write
public void write(b[] ,
int off,
int len)
throws IOException
write
public void write(int b)
throws IOException