FileDocCategorySizeDatePackage
XMLStringBuffer.javaAPI DocApache Xerces 3.0.15188Fri Sep 14 20:33:52 BST 2007org.apache.xerces.util

XMLStringBuffer

public class XMLStringBuffer extends org.apache.xerces.xni.XMLString
XMLString is a structure used to pass character arrays. However, XMLStringBuffer is a buffer in which characters can be appended and extends XMLString so that it can be passed to methods expecting an XMLString object. This is a safe operation because it is assumed that any callee will not modify the contents of the XMLString structure.

The contents of the string are managed by the string buffer. As characters are appended, the string buffer will grow as needed.

Note: Never set the ch, offset, and length fields directly. These fields are managed by the string buffer. In order to reset the buffer, call clear().

author
Andy Clark, IBM
author
Eric Ye, IBM
version
$Id: XMLStringBuffer.java 447241 2006-09-18 05:12:57Z mrglavas $

Fields Summary
public static final int
DEFAULT_SIZE
Default buffer size (32).
Constructors Summary
public XMLStringBuffer()


    //
    // Constructors
    //

          
      
        this(DEFAULT_SIZE);
    
public XMLStringBuffer(int size)

param
size

        ch = new char[size];
    
public XMLStringBuffer(char c)
Constructs a string buffer from a char.

        this(1);
        append(c);
    
public XMLStringBuffer(String s)
Constructs a string buffer from a String.

        this(s.length());
        append(s);
    
public XMLStringBuffer(char[] ch, int offset, int length)
Constructs a string buffer from the specified character array.

        this(length);
        append(ch, offset, length);
    
public XMLStringBuffer(org.apache.xerces.xni.XMLString s)
Constructs a string buffer from the specified XMLString.

        this(s.length);
        append(s);
    
Methods Summary
public voidappend(char[] ch, int offset, int length)
append

param
ch
param
offset
param
length

        if (this.length + length > this.ch.length) {
            char[] newch = new char[this.ch.length + length + DEFAULT_SIZE];
            System.arraycopy(this.ch, 0, newch, 0, this.length);
            this.ch = newch;
        }
        System.arraycopy(ch, offset, this.ch, this.length, length);
        this.length += length;
    
public voidappend(org.apache.xerces.xni.XMLString s)
append

param
s

        append(s.ch, s.offset, s.length);
    
public voidappend(char c)
append

param
c

        if (this.length + 1 > this.ch.length) {
                    int newLength = this.ch.length*2;
                    if (newLength < this.ch.length + DEFAULT_SIZE)
                        newLength = this.ch.length + DEFAULT_SIZE;
                    char[] newch = new char[newLength];
                    System.arraycopy(this.ch, 0, newch, 0, this.length);
                    this.ch = newch;
        }
        this.ch[this.length] = c;
        this.length++;
    
public voidappend(java.lang.String s)
append

param
s

        int length = s.length();
        if (this.length + length > this.ch.length) {
            int newLength = this.ch.length*2;
            if (newLength < this.length + length + DEFAULT_SIZE)
                newLength = this.ch.length + length + DEFAULT_SIZE;
            char[] newch = new char[newLength];            
            System.arraycopy(this.ch, 0, newch, 0, this.length);
            this.ch = newch;
        }
        s.getChars(0, length, this.ch, this.length);
        this.length += length;
    
public voidclear()
Clears the string buffer.

        offset = 0;
        length = 0;