com.caucho.server.http
Class ResponseStream

java.lang.Object
  extended by java.io.OutputStream
      extended by com.caucho.vfs.OutputStreamWithBuffer
          extended by com.caucho.server.http.AbstractResponseStream
              extended by com.caucho.server.http.ToByteResponseStream
                  extended by com.caucho.server.http.ResponseStream
All Implemented Interfaces:
ByteAppendable, java.io.Closeable, java.io.Flushable
Direct Known Subclasses:
FastCgiResponseStream, HmuxResponseStream, HttpResponseStream

public abstract class ResponseStream
extends ToByteResponseStream


Field Summary
 
Fields inherited from class com.caucho.server.http.ToByteResponseStream
SIZE
 
Constructor Summary
  ResponseStream()
           
protected ResponseStream(AbstractHttpResponse response)
           
 
Method Summary
 boolean canWrite()
          Response stream is a writable stream.
 void clear()
          Clears the output buffer, including headers if possible.
 void clearBuffer()
          Clears the response buffer.
 void clearClosed()
          Clear the closed state, because of the NOT_MODIFIED
protected  void clearNext()
           
protected  void closeImpl()
          Complete the request.
protected  void closeNext()
           
protected abstract  void closeNextImpl()
           
 void completeCache()
           
protected  java.lang.String dbgId()
           
 void flush()
          Flushes the buffered response to the output stream.
 void flushByte()
          Flushes the buffered response to the output stream.
 void flushChar()
          Flushes the buffered response to the writer.
 void flushNext()
          Flushes the next buffer, leaving the current buffer alone
protected abstract  void flushNextImpl()
           
 byte[] getBuffer()
          Returns the byte buffer.
 int getBufferOffset()
          Returns the byte offset.
protected  java.io.OutputStream getByteCacheStream()
          Sets a byte cache stream.
 CauchoResponse getCauchoResponse()
           
 int getContentLength()
          Returns the written content length
protected abstract  byte[] getNextBuffer()
           
protected abstract  int getNextBufferOffset()
           
protected  int getNextStartOffset()
           
protected  AbstractHttpResponse getResponse()
           
 boolean hasData()
           
 boolean isCauchoResponseStream()
          Returns true for a Caucho response stream.
 boolean isCloseComplete()
          Test if the request is closing.
 boolean isCommitted()
          Test if data has been flushed to the client.
protected  boolean isDisableAutoFlush()
           
protected  boolean isNextValid()
           
 void killCaching()
           
 byte[] nextBuffer(int offset)
          Sets the next buffer
 void setAutoFlush(boolean isAutoFlush)
          Sets the auto-flush
 void setBufferOffset(int offset)
          Sets the byte offset.
 void setBufferSize(int size)
          Sets the buffer capacity.
 void setByteCacheStream(java.io.OutputStream cacheStream)
          Sets the underlying cache stream for a cached request.
protected  boolean setFlush(boolean flush)
           
protected  void setNextBufferOffset(int offset)
           
protected abstract  void setNextBufferOffsetImpl(int offset)
           
 void setProxyCacheResponse(CauchoResponse response)
           
 void setResponse(AbstractHttpResponse response)
           
 void start()
          initializes the Response stream at the beginning of a request.
protected  void startCaching(boolean isByte)
          Called to start caching.
 java.lang.String toString()
           
 void write(int ch)
          Writes a byte to the output.
protected  void writeHeaders(int length)
          Writes any http headers.
protected  void writeNext(byte[] buf, int offset, int length, boolean isFinished)
          Writes the next chunk of data to the response stream.
protected  byte[] writeNextBuffer(int offset)
           
protected abstract  byte[] writeNextBufferImpl(int offset)
           
protected  void writeTail(boolean isClose)
           
protected  void writeTailImpl(boolean isClosed)
           
 
Methods inherited from class com.caucho.server.http.ToByteResponseStream
flushBuffer, flushByteBuffer, flushCharBuffer, getBufferLength, getBufferSize, getByteBufferOffset, getCharBuffer, getCharOffset, getRemaining, isCharFlushing, nextCharBuffer, print, print, setCharOffset, setEncoding, setLocale, setOutputStreamOnly, write
 
Methods inherited from class com.caucho.server.http.AbstractResponseStream
close, getCharCacheStream, getEncoding, isAutoFlush, isClosed, isClosing, isHead, sendFile, setCauchoResponse, setCharCacheStream, setCommitted, setHead, toClosing
 
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

ResponseStream

public ResponseStream()

ResponseStream

protected ResponseStream(AbstractHttpResponse response)
Method Detail

setResponse

public void setResponse(AbstractHttpResponse response)

getResponse

protected AbstractHttpResponse getResponse()

setProxyCacheResponse

public void setProxyCacheResponse(CauchoResponse response)

getCauchoResponse

public CauchoResponse getCauchoResponse()

start

public void start()
initializes the Response stream at the beginning of a request.

Overrides:
start in class ToByteResponseStream

isCauchoResponseStream

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

Overrides:
isCauchoResponseStream in class ToByteResponseStream

setByteCacheStream

public void setByteCacheStream(java.io.OutputStream cacheStream)
Sets the underlying cache stream for a cached request.

Overrides:
setByteCacheStream in class AbstractResponseStream
Parameters:
cacheStream - the cache stream.

getByteCacheStream

protected java.io.OutputStream getByteCacheStream()
Description copied from class: AbstractResponseStream
Sets a byte cache stream.

Overrides:
getByteCacheStream in class AbstractResponseStream

canWrite

public boolean canWrite()
Response stream is a writable stream.


setFlush

protected boolean setFlush(boolean flush)
Overrides:
setFlush in class ToByteResponseStream

setAutoFlush

public void setAutoFlush(boolean isAutoFlush)
Description copied from class: AbstractResponseStream
Sets the auto-flush

Overrides:
setAutoFlush in class AbstractResponseStream

isDisableAutoFlush

protected boolean isDisableAutoFlush()
Overrides:
isDisableAutoFlush in class ToByteResponseStream

getContentLength

public final int getContentLength()
Description copied from class: AbstractResponseStream
Returns the written content length

Overrides:
getContentLength in class ToByteResponseStream

setBufferSize

public void setBufferSize(int size)
Description copied from class: ToByteResponseStream
Sets the buffer capacity.

Overrides:
setBufferSize in class ToByteResponseStream

hasData

public boolean hasData()

isCommitted

public boolean isCommitted()
Description copied from class: AbstractResponseStream
Test if data has been flushed to the client.

Overrides:
isCommitted in class AbstractResponseStream

clear

public void clear()
           throws java.io.IOException
Description copied from class: AbstractResponseStream
Clears the output buffer, including headers if possible.

Overrides:
clear in class AbstractResponseStream
Throws:
java.io.IOException

clearBuffer

public void clearBuffer()
Description copied from class: ToByteResponseStream
Clears the response buffer.

Overrides:
clearBuffer in class ToByteResponseStream

isCloseComplete

public boolean isCloseComplete()
Description copied from class: AbstractResponseStream
Test if the request is closing.

Overrides:
isCloseComplete in class AbstractResponseStream

clearClosed

public void clearClosed()
Clear the closed state, because of the NOT_MODIFIED


writeHeaders

protected void writeHeaders(int length)
                     throws java.io.IOException
Description copied from class: ToByteResponseStream
Writes any http headers. Because this may be called multiple times, the implementation needs to ensure the header is written once

Overrides:
writeHeaders in class ToByteResponseStream
Parameters:
length - the current buffer length
Throws:
java.io.IOException

write

public final void write(int ch)
                 throws java.io.IOException
Description copied from class: ToByteResponseStream
Writes a byte to the output.

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

getBuffer

public final byte[] getBuffer()
                       throws java.io.IOException
Returns the byte buffer.

Overrides:
getBuffer in class ToByteResponseStream
Throws:
java.io.IOException

getBufferOffset

public final int getBufferOffset()
                          throws java.io.IOException
Returns the byte offset.

Overrides:
getBufferOffset in class ToByteResponseStream
Throws:
java.io.IOException

setBufferOffset

public final void setBufferOffset(int offset)
                           throws java.io.IOException
Sets the byte offset.

Overrides:
setBufferOffset in class ToByteResponseStream
Throws:
java.io.IOException

nextBuffer

public final byte[] nextBuffer(int offset)
                        throws java.io.IOException
Sets the next buffer

Overrides:
nextBuffer in class ToByteResponseStream
Returns:
the next buffer
Throws:
java.io.IOException

writeNext

protected final void writeNext(byte[] buf,
                               int offset,
                               int length,
                               boolean isFinished)
                        throws java.io.IOException
Writes the next chunk of data to the response stream.

Specified by:
writeNext in class ToByteResponseStream
Parameters:
buf - the buffer containing the data
offset - start offset into the buffer
length - length of the data in the buffer
Throws:
java.io.IOException

flush

public final void flush()
                 throws java.io.IOException
Flushes the buffered response to the output stream.

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

flushByte

public void flushByte()
               throws java.io.IOException
Flushes the buffered response to the output stream.

Overrides:
flushByte in class AbstractResponseStream
Throws:
java.io.IOException

flushChar

public void flushChar()
               throws java.io.IOException
Flushes the buffered response to the writer.

Overrides:
flushChar in class AbstractResponseStream
Throws:
java.io.IOException

closeImpl

protected void closeImpl()
                  throws java.io.IOException
Complete the request.

Overrides:
closeImpl in class ToByteResponseStream
Throws:
java.io.IOException

startCaching

protected void startCaching(boolean isByte)
Called to start caching.


killCaching

public void killCaching()
Overrides:
killCaching in class AbstractResponseStream

completeCache

public void completeCache()
Overrides:
completeCache in class AbstractResponseStream

isNextValid

protected final boolean isNextValid()

clearNext

protected void clearNext()

getNextBuffer

protected abstract byte[] getNextBuffer()

getNextStartOffset

protected int getNextStartOffset()

getNextBufferOffset

protected abstract int getNextBufferOffset()
                                    throws java.io.IOException
Throws:
java.io.IOException

setNextBufferOffset

protected final void setNextBufferOffset(int offset)
                                  throws java.io.IOException
Throws:
java.io.IOException

setNextBufferOffsetImpl

protected abstract void setNextBufferOffsetImpl(int offset)
                                         throws java.io.IOException
Throws:
java.io.IOException

writeNextBuffer

protected final byte[] writeNextBuffer(int offset)
                                throws java.io.IOException
Throws:
java.io.IOException

writeNextBufferImpl

protected abstract byte[] writeNextBufferImpl(int offset)
                                       throws java.io.IOException
Throws:
java.io.IOException

flushNext

public final void flushNext()
                     throws java.io.IOException
Description copied from class: AbstractResponseStream
Flushes the next buffer, leaving the current buffer alone

Overrides:
flushNext in class AbstractResponseStream
Throws:
java.io.IOException

flushNextImpl

protected abstract void flushNextImpl()
                               throws java.io.IOException
Throws:
java.io.IOException

closeNext

protected final void closeNext()
                        throws java.io.IOException
Throws:
java.io.IOException

closeNextImpl

protected abstract void closeNextImpl()
                               throws java.io.IOException
Throws:
java.io.IOException

writeTail

protected final void writeTail(boolean isClose)
                        throws java.io.IOException
Throws:
java.io.IOException

writeTailImpl

protected void writeTailImpl(boolean isClosed)
                      throws java.io.IOException
Throws:
java.io.IOException

dbgId

protected java.lang.String dbgId()

toString

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