org.apache.tapestry.request
Class ResponseOutputStream

java.lang.Object
  extended by java.io.OutputStream
      extended by org.apache.tapestry.request.ResponseOutputStream
All Implemented Interfaces:
Closeable, Flushable

public class ResponseOutputStream
extends OutputStream

A special output stream works with a HttpServletResponse, buffering data so as to defer opening the response's output stream.

The buffering is pretty simple because the code between IMarkupWriter and this shows lots of buffering after the PrintWriter and inside the OutputStreamWriter that can't be configured.

This class performs some buffering, but it is not all that useful because the Body component (which will be used on virtually all Tapestry pages), buffers its wrapped contents (that is, evertyhing inside the <body> tag in the generated HTML).

Version:
$Id: ResponseOutputStream.java 243791 2004-02-19 17:38:13Z hlship $
Author:
Howard Lewis Ship

Field Summary
static int DEFAULT_SIZE
          Default size for the buffer (2000 bytes).
 
Constructor Summary
ResponseOutputStream(HttpServletResponse response)
          Creates the stream with the default maximum buffer size.
ResponseOutputStream(HttpServletResponse response, int maxSize)
          Standard constructor.
 
Method Summary
 void close()
          Does nothing.
 void flush()
          Flushes the underlying output stream, if is has been opened.
 void forceFlush()
          Writes the internal buffer to the output stream, opening it if necessary, then flushes the output stream.
 String getContentType()
           
 boolean getDiscard()
           
 void reset()
          Discards all output in the buffer.
 void setBufferSize(int value)
          Changes the maximum buffer size.
 void setContentType(String value)
           
 void setDiscard(boolean value)
          Indicates whether the stream should ignore all data written to it.
 void write(byte[] b, int off, int len)
           
 void write(int b)
           
 
Methods inherited from class java.io.OutputStream
write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_SIZE

public static final int DEFAULT_SIZE
Default size for the buffer (2000 bytes).

See Also:
Constant Field Values
Constructor Detail

ResponseOutputStream

public ResponseOutputStream(HttpServletResponse response)
Creates the stream with the default maximum buffer size.


ResponseOutputStream

public ResponseOutputStream(HttpServletResponse response,
                            int maxSize)
Standard constructor.

Method Detail

close

public void close()
           throws IOException
Does nothing. This is because of chaining of close() from IMarkupWriter.close() ... see flush().

Specified by:
close in interface Closeable
Overrides:
close in class OutputStream
Throws:
IOException

flush

public void flush()
           throws IOException
Flushes the underlying output stream, if is has been opened.

This method explicitly does not flush the internal buffer ... that's because when an IMarkupWriter is closed (for instance, because an exception is thrown), that close() spawns flush()es and close()s throughout the output stream chain, eventually reaching this method.

Specified by:
flush in interface Flushable
Overrides:
flush in class OutputStream
Throws:
IOException
See Also:
forceFlush()

forceFlush

public void forceFlush()
                throws IOException
Writes the internal buffer to the output stream, opening it if necessary, then flushes the output stream. Future writes will go directly to the output stream.

Throws:
IOException

getContentType

public String getContentType()

getDiscard

public boolean getDiscard()

reset

public void reset()
           throws IOException
Discards all output in the buffer. This is used after an error to restart the output (so that the error may be presented).

Clears the discard flag.

Throws:
IOException

setBufferSize

public void setBufferSize(int value)
                   throws IOException
Changes the maximum buffer size. If the new buffer size is smaller than the number of bytes already in the buffer, the buffer is immediately flushed.

Throws:
IOException

setContentType

public void setContentType(String value)

setDiscard

public void setDiscard(boolean value)
Indicates whether the stream should ignore all data written to it.


write

public void write(byte[] b,
                  int off,
                  int len)
           throws IOException
Overrides:
write in class OutputStream
Throws:
IOException

write

public void write(int b)
           throws IOException
Specified by:
write in class OutputStream
Throws:
IOException