com.caucho.server.connection
Class ToByteResponseStream

java.lang.Object
  extended by java.io.OutputStream
      extended by com.caucho.vfs.OutputStreamWithBuffer
          extended by com.caucho.server.connection.AbstractResponseStream
              extended by com.caucho.server.connection.ToByteResponseStream
All Implemented Interfaces:
java.io.Closeable, java.io.Flushable
Direct Known Subclasses:
FilterWrapperResponseStream, IncludeResponseStream, StreamWrapperResponseStream

public abstract class ToByteResponseStream
extends AbstractResponseStream

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


Field Summary
protected  boolean _isFinished
           
protected static int SIZE
           
 
Constructor Summary
protected ToByteResponseStream()
           
 
Method Summary
 void clearBuffer()
          Clears the response buffer.
 void clearClose()
          Clears the close.
 void close()
          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 remaining value left.
 int getBufferOffset()
          Returns the byte offset.
 int getBufferSize()
          Returns the buffer capacity.
 char[] getCharBuffer()
          Returns the char buffer.
 int getCharOffset()
          Returns the char offset.
 int getRemaining()
          Returns the remaining value left.
 boolean isCauchoResponseStream()
          Returns true for a caucho response stream.
 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.
 void setHead()
          Sets the head.
 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 character to the output.
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.connection.AbstractResponseStream
clear, clearClosed, finish, flushByte, flushChar, getContentLength, isAutoFlush, isCommitted, isHead, sendFile, setAutoFlush, setByteCacheStream, setCharCacheStream
 
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

SIZE

protected static final int SIZE

_isFinished

protected boolean _isFinished
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

setHead

public void setHead()
Sets the head.

Overrides:
setHead in class AbstractResponseStream

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

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 remaining value left.


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 character to the output.

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 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

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

close

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

Specified by:
close in interface java.io.Closeable
Overrides:
close 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

flushCharBuffer

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

Throws:
java.io.IOException

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

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

clearClose

public void clearClose()
Clears the close.