org.mortbay.http

Class BufferedOutputStream

Implemented Interfaces:
HttpMessage.HeaderWriter
Known Direct Subclasses:
AJP13OutputStream, ChunkingOutputStream

public class BufferedOutputStream
extends ByteBufferOutputStream
implements HttpMessage.HeaderWriter

Buffered Output Stream. Uses ByteBufferOutputStream to allow pre and post writes.
Version:
$Revision: 1.6 $
Author:
Greg Wilkins (gregw)

Field Summary

protected ByteArrayISO8859Writer
_httpMessageWriter
protected OutputStream
_out

Fields inherited from class org.mortbay.util.ByteBufferOutputStream

_buf

Constructor Summary

BufferedOutputStream(OutputStream out, int capacity, int headerReserve, int preReserve, int postReserve)
Constructor.

Method Summary

protected void
bypassWrite(byte[] b, int offset, int length)
void
close()
void
destroy()
void
flush()
This implementation calls the commitObserver on the first flush since construction or reset.
boolean
getBypassBuffer()
OutputObserver
getCommitObserver()
OutputStream
getOutputStream()
boolean
isCommitted()
void
resetStream()
void
setBypassBuffer(boolean bypassBuffer)
void
setCommitObserver(OutputObserver commitObserver)
protected void
wrapBuffer()
Wrap Buffer.
void
write(byte[] b)
void
write(byte[] b, int offset, int length)
void
writeHeader(HttpMessage httpMessage)

Methods inherited from class org.mortbay.util.ByteBufferOutputStream

bufferSize, capacity, close, destroy, ensureCapacity, ensureReserve, ensureSize, ensureSize, ensureSpareCapacity, flush, isFixed, postReserve, postwrite, preReserve, prewrite, prewrite, prewrite, reset, resetStream, setFixed, size, spareCapacity, write, write, write, writeTo

Field Details

_httpMessageWriter

protected ByteArrayISO8859Writer _httpMessageWriter

_out

protected OutputStream _out

Constructor Details

BufferedOutputStream

public BufferedOutputStream(OutputStream out,
                            int capacity,
                            int headerReserve,
                            int preReserve,
                            int postReserve)
Constructor.
Parameters:
out - the OutputStream to buffer to.
capacity - Buffer capacity.
headerReserve - The reserve of bytes for prepending to be used for the first buffer after reset
preReserve - The reserve of bytes for prepending
postReserve - The reserve of bytes for appending

Method Details

bypassWrite

protected void bypassWrite(byte[] b,
                           int offset,
                           int length)
            throws IOException

close

public void close()
            throws IOException
Overrides:
close in interface ByteBufferOutputStream

destroy

public void destroy()
Overrides:
destroy in interface ByteBufferOutputStream

flush

public void flush()
            throws IOException
This implementation calls the commitObserver on the first flush since construction or reset.
Overrides:
flush in interface ByteBufferOutputStream

getBypassBuffer

public boolean getBypassBuffer()
Returns:
If true, the buffer is bypassed for large writes to a committed stream.

getCommitObserver

public OutputObserver getCommitObserver()
Returns:
OutputObserver to receives commit events from this stream.

getOutputStream

public OutputStream getOutputStream()

isCommitted

public boolean isCommitted()

resetStream

public void resetStream()
Overrides:
resetStream in interface ByteBufferOutputStream

setBypassBuffer

public void setBypassBuffer(boolean bypassBuffer)
Parameters:
bypassBuffer - If true, the buffer is bypassed for large writes to a committed stream.

setCommitObserver

public void setCommitObserver(OutputObserver commitObserver)
Parameters:
commitObserver - OutputObserver to receives commit events from this stream.

wrapBuffer

protected void wrapBuffer()
            throws IOException
Wrap Buffer. Called by flush() to allow the data in the buffer to be pre and post written for any protocol wrapping. The default implementation does nothing.

write

public void write(byte[] b)
            throws IOException
Overrides:
write in interface ByteBufferOutputStream

write

public void write(byte[] b,
                  int offset,
                  int length)
            throws IOException
Overrides:
write in interface ByteBufferOutputStream

writeHeader

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

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