1 25 26 package org.apache.jasper.xmlparser; 27 28 49 public class XMLStringBuffer 50 extends XMLString { 51 52 56 57 public static final int DEFAULT_SIZE = 32; 58 59 63 66 public XMLStringBuffer() { 67 this(DEFAULT_SIZE); 68 } 70 75 public XMLStringBuffer(int size) { 76 ch = new char[size]; 77 } 79 80 public XMLStringBuffer(char c) { 81 this(1); 82 append(c); 83 } 85 86 public XMLStringBuffer(String s) { 87 this(s.length()); 88 append(s); 89 } 91 92 public XMLStringBuffer(char[] ch, int offset, int length) { 93 this(length); 94 append(ch, offset, length); 95 } 97 98 public XMLStringBuffer(XMLString s) { 99 this(s.length); 100 append(s); 101 } 103 107 108 public void clear() { 109 offset = 0; 110 length = 0; 111 } 112 113 118 public void append(char c) { 119 if (this.length + 1 > this.ch.length) { 120 int newLength = this.ch.length*2; 121 if (newLength < this.ch.length + DEFAULT_SIZE) 122 newLength = this.ch.length + DEFAULT_SIZE; 123 char[] newch = new char[newLength]; 124 System.arraycopy(this.ch, 0, newch, 0, this.length); 125 this.ch = newch; 126 } 127 this.ch[this.length] = c; 128 this.length++; 129 } 131 136 public void append(String s) { 137 int length = s.length(); 138 if (this.length + length > this.ch.length) { 139 int newLength = this.ch.length*2; 140 if (newLength < this.length + length + DEFAULT_SIZE) 141 newLength = this.ch.length + length + DEFAULT_SIZE; 142 char[] newch = new char[newLength]; 143 System.arraycopy(this.ch, 0, newch, 0, this.length); 144 this.ch = newch; 145 } 146 s.getChars(0, length, this.ch, this.length); 147 this.length += length; 148 } 150 157 public void append(char[] ch, int offset, int length) { 158 if (this.length + length > this.ch.length) { 159 char[] newch = new char[this.ch.length + length + DEFAULT_SIZE]; 160 System.arraycopy(this.ch, 0, newch, 0, this.length); 161 this.ch = newch; 162 } 163 System.arraycopy(ch, offset, this.ch, this.length, length); 164 this.length += length; 165 } 167 172 public void append(XMLString s) { 173 append(s.ch, s.offset, s.length); 174 } 176 } | Popular Tags |