FileDocCategorySizeDatePackage
XMLStringBuffer.javaAPI DocJava SE 6 API7380Tue Jun 10 00:22:52 BST 2008com.sun.org.apache.xerces.internal.util

XMLStringBuffer

public class XMLStringBuffer extends 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,v 1.1.2.1 2005/08/01 03:35:44 jeffsuttor Exp $

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

    
    //
    // Data
    //
    
    //
    // 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(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) {
            int newLength = this.ch.length * 2 ;
            if(newLength < this.ch.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;
        }
        //making the code more robust as it would handle null or 0 length data,
        //add the data only when it contains some thing
        if(ch != null && length > 0){
            System.arraycopy(ch, offset, this.ch, this.length, length);
            this.length += length;
        }
    
public voidappend(com.sun.org.apache.xerces.internal.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 [] tmp = new char[newLength];
            System.arraycopy(this.ch, 0, tmp, 0, this.length);
            this.ch = tmp;
        }
        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.ch.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;