com.caucho.server.http
Class AbstractResponseStream

java.lang.Object
  extended by java.io.OutputStream
      extended by com.caucho.vfs.OutputStreamWithBuffer
          extended by com.caucho.server.http.AbstractResponseStream
All Implemented Interfaces:
ByteAppendable, java.io.Closeable, java.io.Flushable
Direct Known Subclasses:
BodyResponseStream, StubResponseStream, ToByteResponseStream, ToCharResponseStream, WrapperResponseStream

public abstract class AbstractResponseStream
extends OutputStreamWithBuffer

API for handling the PrintWriter/ServletOutputStream


Constructor Summary
AbstractResponseStream()
           
 
Method Summary
 void clear()
          Clears the output buffer, including headers if possible.
abstract  void clearBuffer()
          Clears the output buffer.
 void close()
          Closes the response stream
protected  void closeImpl()
           
 void completeCache()
           
 void flush()
          Flushes the output.
abstract  void flushBuffer()
          Flushes the output buffer.
 void flushByte()
          Flushes the output.
 void flushChar()
          Flushes the output.
 void flushNext()
          Flushes the next buffer, leaving the current buffer alone
abstract  int getBufferSize()
          Gets the buffer size.
protected  java.io.OutputStream getByteCacheStream()
          Sets a byte cache stream.
abstract  char[] getCharBuffer()
          Returns the char buffer.
protected  java.io.Writer getCharCacheStream()
          Sets a char cache stream.
abstract  int getCharOffset()
          Returns the char buffer offset.
 int getContentLength()
          Returns the written content length
 java.lang.String getEncoding()
           
abstract  int getRemaining()
          Returns the remaining buffer entries.
 boolean isAutoFlush()
          Return the auto-flush.
abstract  boolean isCauchoResponseStream()
          Returns true for a Caucho response stream.
 boolean isCloseComplete()
          Test if the request is closing.
 boolean isClosed()
           
 boolean isClosing()
          Test if the request is closing.
 boolean isCommitted()
          Test if data has been flushed to the client.
 boolean isHead()
          Set true for HEAD requests.
protected  void killCaching()
           
abstract  char[] nextCharBuffer(int offset)
          Returns the next char buffer.
abstract  void print(char[] buffer, int offset, int length)
          Writes a char array to the output.
abstract  void print(int ch)
          Writes a character to the output.
 void sendFile(Path path, long length)
          Sends a file.
 void setAutoFlush(boolean isAutoFlush)
          Sets the auto-flush
abstract  void setBufferSize(int size)
          Sets the buffer size.
 void setByteCacheStream(java.io.OutputStream cacheStream)
          Sets a byte cache stream.
 void setCauchoResponse(CauchoResponse res)
           
 void setCharCacheStream(java.io.Writer cacheStream)
          Sets a char cache stream.
abstract  void setCharOffset(int offset)
          Sets the char buffer offset.
 void setCommitted()
          Sets the committed state
 void setEncoding(java.lang.String encoding)
          Sets the encoding.
 void setHead()
          Set true for HEAD requests.
 void setLocale(java.util.Locale locale)
          Sets the locale.
 void setOutputStreamOnly(boolean isOutputStreamOnly)
          Set true for output stream only request.
 void start()
          Starts the response stream.
protected  boolean toClosing()
           
 java.lang.String toString()
           
abstract  void write(byte[] buffer, int offset, int length)
          Writes a byte array to the output.
abstract  void write(int v)
          Writes a byte to the output.
 
Methods inherited from class com.caucho.vfs.OutputStreamWithBuffer
getBuffer, getBufferOffset, nextBuffer, setBufferOffset
 
Methods inherited from class java.io.OutputStream
write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AbstractResponseStream

public AbstractResponseStream()
Method Detail

setCauchoResponse

public void setCauchoResponse(CauchoResponse res)

start

public void start()
Starts the response stream.


setHead

public void setHead()
Set true for HEAD requests.


isHead

public final boolean isHead()
Set true for HEAD requests.


isCommitted

public boolean isCommitted()
Test if data has been flushed to the client.


setCommitted

public void setCommitted()
Sets the committed state


isClosing

public boolean isClosing()
Test if the request is closing.


isCloseComplete

public boolean isCloseComplete()
Test if the request is closing.


isCauchoResponseStream

public abstract boolean isCauchoResponseStream()
Returns true for a Caucho response stream.


getEncoding

public java.lang.String getEncoding()

setEncoding

public void setEncoding(java.lang.String encoding)
                 throws java.io.UnsupportedEncodingException
Sets the encoding.

Throws:
java.io.UnsupportedEncodingException

setOutputStreamOnly

public void setOutputStreamOnly(boolean isOutputStreamOnly)
Set true for output stream only request.


setLocale

public void setLocale(java.util.Locale locale)
               throws java.io.UnsupportedEncodingException
Sets the locale.

Throws:
java.io.UnsupportedEncodingException

setBufferSize

public abstract void setBufferSize(int size)
Sets the buffer size.


getBufferSize

public abstract int getBufferSize()
Gets the buffer size.


setAutoFlush

public void setAutoFlush(boolean isAutoFlush)
Sets the auto-flush


isAutoFlush

public boolean isAutoFlush()
Return the auto-flush.


getRemaining

public abstract int getRemaining()
Returns the remaining buffer entries.


getCharBuffer

public abstract char[] getCharBuffer()
                              throws java.io.IOException
Returns the char buffer.

Throws:
java.io.IOException

getCharOffset

public abstract int getCharOffset()
                           throws java.io.IOException
Returns the char buffer offset.

Throws:
java.io.IOException

setCharOffset

public abstract void setCharOffset(int offset)
                            throws java.io.IOException
Sets the char buffer offset.

Throws:
java.io.IOException

nextCharBuffer

public abstract char[] nextCharBuffer(int offset)
                               throws java.io.IOException
Returns the next char buffer.

Throws:
java.io.IOException

setByteCacheStream

public void setByteCacheStream(java.io.OutputStream cacheStream)
Sets a byte cache stream.


getByteCacheStream

protected java.io.OutputStream getByteCacheStream()
Sets a byte cache stream.


setCharCacheStream

public void setCharCacheStream(java.io.Writer cacheStream)
Sets a char cache stream.


getCharCacheStream

protected java.io.Writer getCharCacheStream()
Sets a char cache stream.


getContentLength

public int getContentLength()
Returns the written content length


write

public abstract void write(int v)
                    throws java.io.IOException
Writes a byte to the output.

Specified by:
write in interface ByteAppendable
Specified by:
write in class java.io.OutputStream
Throws:
java.io.IOException

write

public abstract void write(byte[] buffer,
                           int offset,
                           int length)
                    throws java.io.IOException
Writes a byte array to the output.

Specified by:
write in interface ByteAppendable
Overrides:
write in class java.io.OutputStream
Throws:
java.io.IOException

print

public abstract void print(int ch)
                    throws java.io.IOException
Writes a character to the output.

Throws:
java.io.IOException

print

public abstract void print(char[] buffer,
                           int offset,
                           int length)
                    throws java.io.IOException
Writes a char array to the output.

Throws:
java.io.IOException

clear

public void clear()
           throws java.io.IOException
Clears the output buffer, including headers if possible.

Throws:
java.io.IOException

clearBuffer

public abstract void clearBuffer()
Clears the output buffer.


flushBuffer

public abstract void flushBuffer()
                          throws java.io.IOException
Flushes the output buffer.

Throws:
java.io.IOException

flushNext

public void flushNext()
               throws java.io.IOException
Flushes the next buffer, leaving the current buffer alone

Throws:
java.io.IOException

flushByte

public void flushByte()
               throws java.io.IOException
Flushes the output.

Throws:
java.io.IOException

flushChar

public void flushChar()
               throws java.io.IOException
Flushes the output.

Throws:
java.io.IOException

sendFile

public void sendFile(Path path,
                     long length)
              throws java.io.IOException
Sends a file.

Parameters:
path - the path to the file
length - the length of the file (-1 if unknown)
Throws:
java.io.IOException

flush

public void flush()
           throws java.io.IOException
Flushes the output.

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

killCaching

protected void killCaching()

completeCache

public void completeCache()

isClosed

public boolean isClosed()
Specified by:
isClosed in class OutputStreamWithBuffer

close

public final void close()
                 throws java.io.IOException
Closes the response stream

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

toClosing

protected boolean toClosing()

closeImpl

protected void closeImpl()
                  throws java.io.IOException
Throws:
java.io.IOException

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object