org.openqa.jetty.http
Class BufferedOutputStream

java.lang.Object
  extended by java.io.OutputStream
      extended by org.openqa.jetty.util.ByteBufferOutputStream
          extended by org.openqa.jetty.http.BufferedOutputStream
All Implemented Interfaces:
Closeable, 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  OutputStream _out
           
 
Fields inherited from class org.openqa.jetty.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.openqa.jetty.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 OutputStream _out

_httpMessageWriter

protected ByteArrayISO8859Writer _httpMessageWriter
Constructor Detail

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 Detail

getOutputStream

public 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 IOException
Specified by:
writeHeader in interface HttpMessage.HeaderWriter
Throws:
IOException

write

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

write

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

bypassWrite

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

flush

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

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

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.

Throws:
IOException

close

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

resetStream

public void resetStream()
Overrides:
resetStream in class ByteBufferOutputStream

destroy

public void destroy()
Overrides:
destroy in class ByteBufferOutputStream


Copyright © 2012. All Rights Reserved.