org.apache.jasper.runtime
Class CharBuffer

java.lang.Object
  extended by org.apache.jasper.runtime.CharBuffer

public class CharBuffer
extends java.lang.Object

An efficient character buffer class. This class is not thread-safe, so its clients will have to take care of any necessary thread issues.

Author:
Brian Remmington

Constructor Summary
CharBuffer(int initialCapacity)
          Create a new character buffer, specifying its initial capacity.
CharBuffer(int initialCapacity, int minimumGrowth)
          Create a new character buffer, specifying its initial capacity and minimum growth.
 
Method Summary
 void buffer(char character)
          Add the supplied character to this buffer, growing the buffer if necessary.
 void buffer(char[] characters, int start, int length)
          Add a section of the supplied character array to this buffer, growing the buffer if necessary.
 void buffer(java.lang.String text, int start, int length)
          Add a substring of the supplied string to this buffer, growing the buffer if necessary.
 void clear()
          Clear this buffer.
 int getCapacity()
          Find the current capacity of this buffer.
 int size()
          Obtain the current size of this buffer.
 char[] toArray()
          Render this buffer as a character array.
 java.lang.String toString()
          Render this buffer as a String.
 void writeOut(java.io.Writer writer)
          Write the content of this buffer out to the supplied Writer object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

CharBuffer

public CharBuffer(int initialCapacity)
Create a new character buffer, specifying its initial capacity. If this buffer ever has to grow then it will grow by at least the same as its initial capacity again

Parameters:
initialCapacity -

CharBuffer

public CharBuffer(int initialCapacity,
                  int minimumGrowth)
Create a new character buffer, specifying its initial capacity and minimum growth.

Parameters:
initialCapacity - The number of characters initially provisioned for.
minimumGrowth - The smallest number of characters by which the buffer will grow. If zero is specified then the value of the initial capacity will be used.
Method Detail

buffer

public void buffer(char character)
Add the supplied character to this buffer, growing the buffer if necessary.

Parameters:
character -

buffer

public void buffer(java.lang.String text,
                   int start,
                   int length)
            throws java.lang.IllegalArgumentException
Add a substring of the supplied string to this buffer, growing the buffer if necessary.

Parameters:
text - The original String that is to be added to the buffer.
start - The index of the starting character to add to the buffer (zero-based).
length - The number of characters to add to the buffer.
Throws:
java.lang.IllegalArgumentException - If text is null, start points beyond end of text, or start + length goes beyond end of text.

buffer

public void buffer(char[] characters,
                   int start,
                   int length)
            throws java.lang.IllegalArgumentException
Add a section of the supplied character array to this buffer, growing the buffer if necessary.

Parameters:
characters - The character array that is to be added to the buffer.
start - The index of the starting character to add to the buffer (zero-based).
length - The number of characters to add to the buffer.
Throws:
java.lang.IllegalArgumentException - If array is null, start points beyond end of array, or start + length goes beyond end of array.

toArray

public char[] toArray()
Render this buffer as a character array.

Returns:

toString

public java.lang.String toString()
Render this buffer as a String.

Overrides:
toString in class java.lang.Object

getCapacity

public int getCapacity()
Find the current capacity of this buffer.

Returns:
The capacity of this buffer. This is the number of characters that can be added to this buffer without it having to grow.

size

public int size()
Obtain the current size of this buffer.

Returns:
The number of characters that are currently in this buffer. Equates to the size of array that would be returned by toArray() or the length of String returned by toString().

clear

public void clear()
Clear this buffer. Upon return, a call to size() will return zero.


writeOut

public void writeOut(java.io.Writer writer)
              throws java.io.IOException,
                     java.lang.IllegalArgumentException
Write the content of this buffer out to the supplied Writer object. This will not flush the writer before returning.

Parameters:
writer - The writer in to which the buffer should be written.
Throws:
java.io.IOException - If any error occurs while writing the buffer into the stream.
java.lang.IllegalArgumentException - If 'writer' is null.


Copyright © 2000-2009 Apache Software Foundation. All Rights Reserved.