org.mortbay.http

Class HttpOutputStream

Implemented Interfaces:
HttpMessage.HeaderWriter, OutputObserver

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.26 2005/08/13 00:01:24 gregwilkins Exp $
Author:
Greg Wilkins

Field Summary

static Class[]
__filterArg

Fields inherited from interface org.mortbay.util.OutputObserver

__CLOSED, __CLOSING, __COMMITING, __FIRST_WRITE, __RESET_BUFFER

Constructor Summary

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

Method Summary

void
addObserver(OutputObserver observer)
Add an Output Observer.
void
addObserver(OutputObserver observer, Object data)
Add an Output Observer.
protected void
checkOutput()
void
close()
Close the stream.
void
destroy()
void
flush()
int
getBufferSize()
Get the output buffer capacity.
OutputStream
getBufferedOutputStream()
Get the buffered output stream.
int
getBytesWritten()
OutputStream
getOutputStream()
Get the backing output stream.
Writer
getWriter(String encoding)
boolean
isChunking()
Get chunking mode
boolean
isClosed()
Close the stream.
boolean
isNullOutput()
is the output Nulled?
boolean
isWritten()
Has any data been written to the stream.
void
nullOutput()
Null the output.
void
outputNotify(OutputStream out, int action, Object ignoredData)
Output Notification.
protected int
prepareOutput(int length)
void
resetBuffer()
Reset Buffered output.
void
resetObservers()
Reset the observers.
void
resetStream()
Reset the stream.
void
setBufferSize(int size)
Set the output buffer size.
void
setBufferedOutputStream(BufferedOutputStream bos)
void
setChunking()
Set chunking mode.
void
setContentLength(int length)
String
toString()
void
write(InputStream in, int len)
void
write(b[] )
void
write(b[] , int off, int len)
void
write(int b)
void
writeHeader(HttpMessage httpMessage)

Field Details

__filterArg

public static final Class[] __filterArg

Constructor Details

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 Details

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()
            throws IOException
Close the stream.

destroy

public void destroy()

flush

public void flush()
            throws IOException

getBufferSize

public int getBufferSize()
Get the output buffer capacity.
Returns:
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.
Returns:
Raw OutputStream.

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.
Returns:
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.
Specified by:
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.
Parameters:
size - Minimum buffer size in bytes

setBufferedOutputStream

public void setBufferedOutputStream(BufferedOutputStream bos)

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

writeHeader

public void writeHeader(HttpMessage httpMessage)
            throws IOException
Specified by:
writeHeader in interface HttpMessage.HeaderWriter

Copyright © 2004 Mortbay Consulting Pty. Ltd. All Rights Reserved.