org.mortbay.http
Class BufferedOutputStream

java.lang.Object
  extended by java.io.OutputStream
      extended by org.mortbay.util.ByteBufferOutputStream
          extended by org.mortbay.http.BufferedOutputStream
All Implemented Interfaces:
java.io.Closeable, java.io.Flushable, HttpMessage.HeaderWriter
Direct Known 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.8 $
Author:
Greg Wilkins (gregw)

Field Summary
protected  ByteArrayISO8859Writer _httpMessageWriter
           
protected  java.io.OutputStream _out
           
 
Fields inherited from class org.mortbay.util.ByteBufferOutputStream
_buf
 
Constructor Summary
BufferedOutputStream(java.io.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()
           
 java.io.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, ensureCapacity, ensureReserve, ensureSize, ensureSize, ensureSpareCapacity, isFixed, postReserve, postwrite, postwrite, preReserve, prewrite, prewrite, prewrite, reset, setFixed, size, spareCapacity, write, writeTo
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_out

protected java.io.OutputStream _out

_httpMessageWriter

protected ByteArrayISO8859Writer _httpMessageWriter
Constructor Detail

BufferedOutputStream

public BufferedOutputStream(java.io.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 Detail

getOutputStream

public java.io.OutputStream getOutputStream()

getCommitObserver

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

setCommitObserver

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

isCommitted

public boolean isCommitted()

getBypassBuffer

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

setBypassBuffer

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

writeHeader

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

write

public void write(byte[] b)
           throws java.io.IOException
Overrides:
write in class ByteBufferOutputStream
Throws:
java.io.IOException

write

public void write(byte[] b,
                  int offset,
                  int length)
           throws java.io.IOException
Overrides:
write in class ByteBufferOutputStream
Throws:
java.io.IOException

bypassWrite

protected void bypassWrite(byte[] b,
                           int offset,
                           int length)
                    throws java.io.IOException
Throws:
java.io.IOException

flush

public void flush()
           throws java.io.IOException
This implementation calls the commitObserver on the first flush since construction or reset.

Specified by:
flush in interface java.io.Flushable
Overrides:
flush in class ByteBufferOutputStream
Throws:
java.io.IOException

wrapBuffer

protected void wrapBuffer()
                   throws java.io.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.

Throws:
java.io.IOException

close

public void close()
           throws java.io.IOException
Specified by:
close in interface java.io.Closeable
Overrides:
close in class ByteBufferOutputStream
Throws:
java.io.IOException

resetStream

public void resetStream()
Overrides:
resetStream in class ByteBufferOutputStream

destroy

public void destroy()
Overrides:
destroy in class ByteBufferOutputStream


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