org.mortbay.http

Class HttpOutputStream

public class HttpOutputStream extends OutputStream implements OutputObserver, HttpMessage.HeaderWriter

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: This class is not synchronized and should be synchronized explicitly if an instance is used by multiple threads.

Version: $Id: HttpOutputStream.java,v 1.28 2006/10/08 14:13:05 gregwilkins Exp $

Author: Greg Wilkins

Field Summary
static Class[]__filterArg
Constructor Summary
HttpOutputStream(OutputStream outputStream)
Constructor.
HttpOutputStream(OutputStream outputStream, int bufferSize)
Constructor.
HttpOutputStream(OutputStream outputStream, int bufferSize, int headerReserve)
Constructor.
Method Summary
voidaddObserver(OutputObserver observer)
Add an Output Observer.
voidaddObserver(OutputObserver observer, Object data)
Add an Output Observer.
protected voidcheckOutput()
voidclose()
Close the stream.
voiddestroy()
voidflush()
OutputStreamgetBufferedOutputStream()
Get the buffered output stream.
intgetBufferSize()
Get the output buffer capacity.
intgetBytesWritten()
OutputStreamgetOutputStream()
Get the backing output stream.
WritergetWriter(String encoding)
booleanisChunking()
Get chunking mode
booleanisClosed()
Close the stream.
booleanisNullOutput()
is the output Nulled?
booleanisWritten()
Has any data been written to the stream.
voidnullOutput()
Null the output.
voidoutputNotify(OutputStream out, int action, Object ignoredData)
Output Notification.
protected intprepareOutput(int length)
voidresetBuffer()
Reset Buffered output.
voidresetObservers()
Reset the observers.
voidresetStream()
Reset the stream.
voidsetBufferedOutputStream(BufferedOutputStream bos)
voidsetBufferSize(int size)
Set the output buffer size.
voidsetChunking()
Set chunking mode.
voidsetContentLength(int length)
StringtoString()
voidwrite(int b)
voidwrite(byte[] b)
voidwrite(byte[] b, int off, int len)
voidwrite(InputStream in, int len)
voidwriteHeader(HttpMessage httpMessage)

Field Detail

__filterArg

public static final Class[] __filterArg

Constructor Detail

HttpOutputStream

public HttpOutputStream(OutputStream outputStream)
Constructor.

Parameters: outputStream The outputStream to buffer or chunk to.

HttpOutputStream

public HttpOutputStream(OutputStream outputStream, int bufferSize)
Constructor.

Parameters: outputStream The outputStream to buffer or chunk to.

HttpOutputStream

public HttpOutputStream(OutputStream outputStream, int bufferSize, int headerReserve)
Constructor.

Parameters: outputStream The outputStream to buffer or chunk to.

Method Detail

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.

Parameters: observer The observer.

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.

Parameters: observer The observer. data Data to be passed wit notify calls.

checkOutput

protected void checkOutput()

close

public void close()
Close the stream.

Throws: IOException

destroy

public void destroy()

flush

public void flush()

getBufferedOutputStream

public OutputStream getBufferedOutputStream()
Get the buffered output stream.

getBufferSize

public int getBufferSize()
Get the output buffer capacity.

Returns: Buffer capacity in bytes.

getBytesWritten

public int getBytesWritten()

getOutputStream

public OutputStream getOutputStream()
Get the backing output stream. A stream without filters or chunking is returned.

Returns: Raw OutputStream.

getWriter

public Writer getWriter(String encoding)

isChunking

public boolean isChunking()
Get chunking mode

isClosed

public boolean isClosed()
Close the stream.

Throws: IOException

isNullOutput

public boolean isNullOutput()
is the output Nulled?

isWritten

public boolean isWritten()
Has any data been written to the stream.

Returns: True if write has been called.

nullOutput

public void nullOutput()
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)
Output Notification. Called by the internal Buffered Output and the event is passed on to this streams observers.

prepareOutput

protected int prepareOutput(int length)

resetBuffer

public void resetBuffer()
Reset Buffered output. If no data has been committed, the buffer output is discarded and the filters may be reinitialized.

Throws: IllegalStateException

resetObservers

public void resetObservers()
Reset the observers.

resetStream

public void resetStream()
Reset the stream. Turn disable all filters.

Throws: IllegalStateException The stream cannot be reset if chunking is enabled.

setBufferedOutputStream

public void setBufferedOutputStream(BufferedOutputStream bos)

setBufferSize

public void setBufferSize(int size)
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.

Parameters: size Minimum buffer size in bytes

Throws: IllegalStateException If output has been written.

setChunking

public void setChunking()
Set chunking mode.

setContentLength

public void setContentLength(int length)

toString

public String toString()

write

public void write(int b)

write

public void write(byte[] b)

write

public void write(byte[] b, int off, int len)

write

public void write(InputStream in, int len)

writeHeader

public void writeHeader(HttpMessage httpMessage)
Copyright © 2004 Mortbay Consulting Pty. Ltd. All Rights Reserved.