com.caucho.server.http
Class ToByteResponseStream

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
All Implemented Interfaces:
ByteAppendable, java.io.Closeable, java.io.Flushable
Direct Known Subclasses:
FilterWrapperResponseStream, IncludeResponseStream2, ResponseStream, StreamWrapperResponseStream

public abstract class ToByteResponseStream
extends AbstractResponseStream

Handles the dual char/byte buffering for the response stream.


Field Summary
protected static int SIZE
           
 
Constructor Summary
protected ToByteResponseStream()
           
 
Method Summary
 void clearBuffer()
          Clears the response buffer.
protected  void closeImpl()
          Closes the response stream.
 void flush()
          Flushes the buffered response to the output stream.
 void flushBuffer()
          Flushes the buffer.
protected  void flushByteBuffer()
          Flushes the buffered response to the output stream.
protected  void flushCharBuffer()
          Converts the char buffer.
 byte[] getBuffer()
          Returns the byte buffer.
protected  int getBufferLength()
          Returns the data in the buffer
 int getBufferOffset()
          Returns the byte offset.
 int getBufferSize()
          Returns the buffer capacity.
 int getByteBufferOffset()
          Returns the byte offset.
 char[] getCharBuffer()
          Returns the char buffer.
 int getCharOffset()
          Returns the char offset.
 int getContentLength()
          Returns the written content length
 int getRemaining()
          Returns the remaining value left.
 boolean isCauchoResponseStream()
          Returns true for a caucho response stream.
protected  boolean isCharFlushing()
          True while the char buffer is being flushed, needed for content-length vs chunked headers.
protected  boolean isDisableAutoFlush()
           
 byte[] nextBuffer(int offset)
          Returns the next byte buffer.
 char[] nextCharBuffer(int offset)
          Converts the char buffer.
 void print(char[] buffer, int offset, int length)
          Writes a char array to the output.
 void print(int ch)
          Writes a character to the output.
 void setBufferOffset(int offset)
          Sets the byte offset.
 void setBufferSize(int size)
          Sets the buffer capacity.
 void setCharOffset(int offset)
          Sets the char offset.
 void setEncoding(java.lang.String encoding)
          Sets the encoding.
protected  boolean setFlush(boolean isAllowFlush)
           
 void setLocale(java.util.Locale locale)
          Sets the locale.
 void setOutputStreamOnly(boolean isOutputStreamOnly)
          Set true for output stream only request.
 void start()
          Initializes the Buffered Response stream at the beginning of a request.
 void write(byte[] buffer, int offset, int length)
          Writes a chunk of bytes to the stream.
 void write(int ch)
          Writes a byte to the output.
protected  void writeHeaders(int length)
          Writes any http headers.
protected abstract  void writeNext(byte[] buffer, int offset, int length, boolean isEnd)
          Writes the chunk to the downward stream.
 
Methods inherited from class com.caucho.server.http.AbstractResponseStream
clear, close, completeCache, flushByte, flushChar, flushNext, getByteCacheStream, getCharCacheStream, getEncoding, isAutoFlush, isCloseComplete, isClosed, isClosing, isCommitted, isHead, killCaching, sendFile, setAutoFlush, setByteCacheStream, setCauchoResponse, setCharCacheStream, setCommitted, setHead, toClosing, toString
 
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
 

Field Detail

SIZE

protected static final int SIZE
Constructor Detail

ToByteResponseStream

protected ToByteResponseStream()
Method Detail

start

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

Overrides:
start in class AbstractResponseStream

isCauchoResponseStream

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

Specified by:
isCauchoResponseStream in class AbstractResponseStream

setOutputStreamOnly

public void setOutputStreamOnly(boolean isOutputStreamOnly)
Description copied from class: AbstractResponseStream
Set true for output stream only request.

Overrides:
setOutputStreamOnly in class AbstractResponseStream

setFlush

protected boolean setFlush(boolean isAllowFlush)

setEncoding

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

Overrides:
setEncoding in class AbstractResponseStream
Throws:
java.io.UnsupportedEncodingException

setLocale

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

Overrides:
setLocale in class AbstractResponseStream
Throws:
java.io.UnsupportedEncodingException

getCharBuffer

public final char[] getCharBuffer()
Returns the char buffer.

Specified by:
getCharBuffer in class AbstractResponseStream

getCharOffset

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

Specified by:
getCharOffset in class AbstractResponseStream
Throws:
java.io.IOException

setCharOffset

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

Specified by:
setCharOffset in class AbstractResponseStream
Throws:
java.io.IOException

getBuffer

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

Specified by:
getBuffer in class OutputStreamWithBuffer
Throws:
java.io.IOException

getBufferOffset

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

Specified by:
getBufferOffset in class OutputStreamWithBuffer
Throws:
java.io.IOException

getByteBufferOffset

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

Throws:
java.io.IOException

setBufferOffset

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

Specified by:
setBufferOffset in class OutputStreamWithBuffer
Throws:
java.io.IOException

getBufferSize

public int getBufferSize()
Returns the buffer capacity.

Specified by:
getBufferSize in class AbstractResponseStream

setBufferSize

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

Specified by:
setBufferSize in class AbstractResponseStream

getRemaining

public int getRemaining()
Returns the remaining value left.

Specified by:
getRemaining in class AbstractResponseStream

getBufferLength

protected int getBufferLength()
Returns the data in the buffer


isDisableAutoFlush

protected boolean isDisableAutoFlush()

clearBuffer

public void clearBuffer()
Clears the response buffer.

Specified by:
clearBuffer in class AbstractResponseStream

write

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

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

write

public void write(byte[] buffer,
                  int offset,
                  int length)
           throws java.io.IOException
Writes a chunk of bytes to the stream.

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

print

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

Specified by:
print in class AbstractResponseStream
Throws:
java.io.IOException

print

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

Specified by:
print in class AbstractResponseStream
Throws:
java.io.IOException

nextCharBuffer

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

Specified by:
nextCharBuffer in class AbstractResponseStream
Throws:
java.io.IOException

isCharFlushing

protected boolean isCharFlushing()
True while the char buffer is being flushed, needed for content-length vs chunked headers.


flushCharBuffer

protected void flushCharBuffer()
                        throws java.io.IOException
Converts the char buffer.

Throws:
java.io.IOException

getContentLength

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

Overrides:
getContentLength in class AbstractResponseStream

nextBuffer

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

Specified by:
nextBuffer in class OutputStreamWithBuffer
Returns:
the next buffer
Throws:
java.io.IOException

flushByteBuffer

protected void flushByteBuffer()
                        throws java.io.IOException
Flushes the buffered response to the output stream.

Throws:
java.io.IOException

writeHeaders

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

Parameters:
length - the current buffer length
Throws:
java.io.IOException

writeNext

protected abstract void writeNext(byte[] buffer,
                                  int offset,
                                  int length,
                                  boolean isEnd)
                           throws java.io.IOException
Writes the chunk to the downward stream.

Throws:
java.io.IOException

flushBuffer

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

Specified by:
flushBuffer in class AbstractResponseStream
Throws:
java.io.IOException

flush

public 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 AbstractResponseStream
Throws:
java.io.IOException

closeImpl

protected void closeImpl()
                  throws java.io.IOException
Closes the response stream.

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