org.apache.tomcat.core
Class OutputBuffer

java.lang.Object
  extended byjava.io.Writer
      extended byorg.apache.tomcat.core.OutputBuffer
All Implemented Interfaces:
ByteChunk.ByteOutputChannel, CharChunk.CharOutputChannel

public class OutputBuffer
extends java.io.Writer
implements ByteChunk.ByteOutputChannel, CharChunk.CharOutputChannel

The buffer used by tomcat response. It allows writting chars and bytes. It does the mixing in order to implement ServletOutputStream ( which has both byte and char methods ) and to allow a number of optimizations (like a jsp pre-computing the byte[], but using char for non-static content).

Author:
Costin Manolache

Field Summary
 int BYTE_STATE
           
 int CHAR_STATE
           
protected  C2BConverter conv
           
static int DEFAULT_BUFFER_SIZE
           
static java.lang.String DEFAULT_ENCODING
           
protected  java.util.Hashtable encoders
           
 int INITIAL_STATE
           
 
Fields inherited from class java.io.Writer
lock
 
Constructor Summary
OutputBuffer()
           
OutputBuffer(int size)
           
 
Method Summary
 void close()
           
 void flush()
           
 void flushBytes()
          Real write - this buffer will be sent to the client
 void flushChars()
           
 boolean flushCharsNeeded()
           
 byte[] getBuffer()
           
 int getBufferSize()
           
 int getByteOff()
          Deprecated. Used only in Ajp13Packet for a hack
 int getBytesWritten()
           
 int getCharsWritten()
           
 boolean isNew()
          True if this buffer hasn't been used ( since recycle() ) - i.e.
protected  void log(java.lang.String s)
           
 void realWriteBytes(byte[] buf, int off, int cnt)
          Sends the buffer data to the client output, checking the state of Response and calling the right interceptors.
 void realWriteChars(char[] c, int off, int len)
          Send the bytes ( usually the internal conversion buffer ).
 void recycle()
           
 void reset()
           
 void setBufferSize(int size)
           
 void setByteOff(int c)
          Deprecated. Used only in Ajp13Packet for a hack
protected  void setConverter()
           
 void setEncoding(java.lang.String s)
           
 void setResponse(Response resp)
           
 void write(byte[] b, int off, int len)
           
 void write(char[] c)
           
 void write(char[] c, int off, int len)
           
 void write(int c)
           
 void write(java.lang.String s)
           
 void write(java.lang.StringBuffer sb)
           
 void write(java.lang.String s, int off, int len)
          Append a string to the buffer
 void writeByte(int b)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_ENCODING

public static final java.lang.String DEFAULT_ENCODING
See Also:
Constant Field Values

DEFAULT_BUFFER_SIZE

public static final int DEFAULT_BUFFER_SIZE
See Also:
Constant Field Values

INITIAL_STATE

public final int INITIAL_STATE
See Also:
Constant Field Values

CHAR_STATE

public final int CHAR_STATE
See Also:
Constant Field Values

BYTE_STATE

public final int BYTE_STATE
See Also:
Constant Field Values

encoders

protected java.util.Hashtable encoders

conv

protected C2BConverter conv
Constructor Detail

OutputBuffer

public OutputBuffer()

OutputBuffer

public OutputBuffer(int size)
Method Detail

setResponse

public void setResponse(Response resp)

getBuffer

public byte[] getBuffer()

getByteOff

public int getByteOff()
Deprecated. Used only in Ajp13Packet for a hack

Return the first available position in the byte buffer ( or the number of bytes written ).


setByteOff

public void setByteOff(int c)
Deprecated. Used only in Ajp13Packet for a hack

Set the write position in the byte buffer


log

protected void log(java.lang.String s)

realWriteBytes

public void realWriteBytes(byte[] buf,
                           int off,
                           int cnt)
                    throws java.io.IOException
Sends the buffer data to the client output, checking the state of Response and calling the right interceptors.

Specified by:
realWriteBytes in interface ByteChunk.ByteOutputChannel
Throws:
java.io.IOException

recycle

public void recycle()

write

public void write(byte[] b,
                  int off,
                  int len)
           throws java.io.IOException
Throws:
java.io.IOException

writeByte

public void writeByte(int b)
               throws java.io.IOException
Throws:
java.io.IOException

write

public void write(int c)
           throws java.io.IOException
Throws:
java.io.IOException

write

public void write(char[] c)
           throws java.io.IOException
Throws:
java.io.IOException

write

public void write(char[] c,
                  int off,
                  int len)
           throws java.io.IOException
Throws:
java.io.IOException

write

public void write(java.lang.StringBuffer sb)
           throws java.io.IOException
Throws:
java.io.IOException

write

public void write(java.lang.String s,
                  int off,
                  int len)
           throws java.io.IOException
Append a string to the buffer

Throws:
java.io.IOException

write

public void write(java.lang.String s)
           throws java.io.IOException
Throws:
java.io.IOException

flushChars

public void flushChars()
                throws java.io.IOException
Throws:
java.io.IOException

flushCharsNeeded

public boolean flushCharsNeeded()

close

public void close()
           throws java.io.IOException
Throws:
java.io.IOException

flush

public void flush()
           throws java.io.IOException
Throws:
java.io.IOException

setEncoding

public void setEncoding(java.lang.String s)

realWriteChars

public void realWriteChars(char[] c,
                           int off,
                           int len)
                    throws java.io.IOException
Description copied from interface: CharChunk.CharOutputChannel
Send the bytes ( usually the internal conversion buffer ). Expect 8k output if the buffer is full.

Specified by:
realWriteChars in interface CharChunk.CharOutputChannel
Throws:
java.io.IOException

setConverter

protected void setConverter()

flushBytes

public void flushBytes()
                throws java.io.IOException
Real write - this buffer will be sent to the client

Throws:
java.io.IOException

getBytesWritten

public int getBytesWritten()

getCharsWritten

public int getCharsWritten()

isNew

public boolean isNew()
True if this buffer hasn't been used ( since recycle() ) - i.e. no chars or bytes have been added to the buffer.


setBufferSize

public void setBufferSize(int size)

reset

public void reset()

getBufferSize

public int getBufferSize()


Copyright ? 2001 Apache Software Foundation. All Rights Reserved.