This commit is contained in:
2024-11-30 19:03:49 +08:00
commit 1e6763c160
3806 changed files with 737676 additions and 0 deletions

View File

@@ -0,0 +1,206 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.jasper.xmlparser;
import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
import org.apache.jasper.compiler.Localizer;
/**
* A simple ASCII byte reader. This is an optimized reader for reading
* byte streams that only contain 7-bit ASCII characters.
*
* @author Andy Clark, IBM
*
* @deprecated Will be removed in Tomcat 9.0.x onwards
*/
@Deprecated
public class ASCIIReader extends Reader {
//
// Data
//
/** Input stream. */
private final InputStream fInputStream;
/** Byte buffer. */
private final byte[] fBuffer;
//
// Constructors
//
/**
* Constructs an ASCII reader from the specified input stream
* and buffer size.
*
* @param inputStream The input stream.
* @param size The initial buffer size.
*/
public ASCIIReader(InputStream inputStream, int size) {
fInputStream = inputStream;
fBuffer = new byte[size];
}
//
// Reader methods
//
/**
* Read a single character. This method will block until a character is
* available, an I/O error occurs, or the end of the stream is reached.
*
* <p> Subclasses that intend to support efficient single-character input
* should override this method.
*
* @return The character read, as an integer in the range 0 to 127
* (<code>0x00-0x7f</code>), or -1 if the end of the stream has
* been reached
*
* @exception IOException If an I/O error occurs
*/
@Override
public int read() throws IOException {
int b0 = fInputStream.read();
if (b0 > 0x80) {
throw new IOException(Localizer.getMessage("jsp.error.xml.invalidASCII",
Integer.toString(b0)));
}
return b0;
} // read():int
/**
* Read characters into a portion of an array. This method will block
* until some input is available, an I/O error occurs, or the end of the
* stream is reached.
*
* @param ch Destination buffer
* @param offset Offset at which to start storing characters
* @param length Maximum number of characters to read
*
* @return The number of characters read, or -1 if the end of the
* stream has been reached
*
* @exception IOException If an I/O error occurs
*/
@Override
public int read(char ch[], int offset, int length) throws IOException {
if (length > fBuffer.length) {
length = fBuffer.length;
}
int count = fInputStream.read(fBuffer, 0, length);
for (int i = 0; i < count; i++) {
int b0 = (0xff & fBuffer[i]); // Convert to unsigned
if (b0 > 0x80) {
throw new IOException(Localizer.getMessage("jsp.error.xml.invalidASCII",
Integer.toString(b0)));
}
ch[offset + i] = (char)b0;
}
return count;
} // read(char[],int,int)
/**
* Skip characters. This method will block until some characters are
* available, an I/O error occurs, or the end of the stream is reached.
*
* @param n The number of characters to skip
*
* @return The number of characters actually skipped
*
* @exception IOException If an I/O error occurs
*/
@Override
public long skip(long n) throws IOException {
return fInputStream.skip(n);
} // skip(long):long
/**
* Tell whether this stream is ready to be read.
*
* @return True if the next read() is guaranteed not to block for input,
* false otherwise. Note that returning false does not guarantee that the
* next read will block.
*
* @exception IOException If an I/O error occurs
*/
@Override
public boolean ready() throws IOException {
return false;
} // ready()
/**
* Tell whether this stream supports the mark() operation.
*/
@Override
public boolean markSupported() {
return fInputStream.markSupported();
} // markSupported()
/**
* Mark the present position in the stream. Subsequent calls to reset()
* will attempt to reposition the stream to this point. Not all
* character-input streams support the mark() operation.
*
* @param readAheadLimit Limit on the number of characters that may be
* read while still preserving the mark. After
* reading this many characters, attempting to
* reset the stream may fail.
*
* @exception IOException If the stream does not support mark(),
* or if some other I/O error occurs
*/
@Override
public void mark(int readAheadLimit) throws IOException {
fInputStream.mark(readAheadLimit);
} // mark(int)
/**
* Reset the stream. If the stream has been marked, then attempt to
* reposition it at the mark. If the stream has not been marked, then
* attempt to reset it in some way appropriate to the particular stream,
* for example by repositioning it to its starting point. Not all
* character-input streams support the reset() operation, and some support
* reset() without supporting mark().
*
* @exception IOException If the stream has not been marked,
* or if the mark has been invalidated,
* or if the stream does not support reset(),
* or if some other I/O error occurs
*/
@Override
public void reset() throws IOException {
fInputStream.reset();
} // reset()
/**
* Close the stream. Once a stream has been closed, further read(),
* ready(), mark(), or reset() invocations will throw an IOException.
* Closing a previously-closed stream, however, has no effect.
*
* @exception IOException If an I/O error occurs
*/
@Override
public void close() throws IOException {
fInputStream.close();
} // close()
} // class ASCIIReader

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,195 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 1999, International
* Business Machines, Inc., http://www.apache.org. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.jasper.xmlparser;
/**
* This class is a symbol table implementation that guarantees that
* strings used as identifiers are unique references. Multiple calls
* to <code>addSymbol</code> will always return the same string
* reference.
* <p>
* The symbol table performs the same task as <code>String.intern()</code>
* with the following differences:
* <ul>
* <li>
* A new string object does not need to be created in order to
* retrieve a unique reference. Symbols can be added by using
* a series of characters in a character array.
* </li>
* <li>
* Users of the symbol table can provide their own symbol hashing
* implementation. For example, a simple string hashing algorithm
* may fail to produce a balanced set of hashcodes for symbols
* that are <em>mostly</em> unique. Strings with similar leading
* characters are especially prone to this poor hashing behavior.
* </li>
* </ul>
*
* @author Andy Clark
*
* @deprecated Will be removed in Tomcat 9.0.x onwards
*/
@Deprecated
public class SymbolTable {
//
// Constants
//
/**
* Default table size.
*/
private static final int TABLE_SIZE = 101;
//
// Data
//
/**
* Buckets.
*/
private final Entry[] fBuckets;
// actual table size
private final int fTableSize;
//
// Constructors
//
/**
* Constructs a symbol table with a default number of buckets.
*/
public SymbolTable() {
this(TABLE_SIZE);
}
/**
* Constructs a symbol table with a specified number of buckets.
* @param tableSize The table size (default is 101)
*/
public SymbolTable(int tableSize) {
fTableSize = tableSize;
fBuckets = new Entry[fTableSize];
}
//
// Public methods
//
/**
* Adds the specified symbol to the symbol table and returns a
* reference to the unique symbol. If the symbol already exists,
* the previous symbol reference is returned instead, in order
* guarantee that symbol references remain unique.
*
* @param buffer The buffer containing the new symbol.
* @param offset The offset into the buffer of the new symbol.
* @param length The length of the new symbol in the buffer.
* @return the symbol added
*/
public String addSymbol(char[] buffer, int offset, int length) {
// search for identical symbol
int bucket = hash(buffer, offset, length) % fTableSize;
OUTER: for (Entry entry = fBuckets[bucket]; entry != null; entry = entry.next) {
if (length == entry.characters.length) {
for (int i = 0; i < length; i++) {
if (buffer[offset + i] != entry.characters[i]) {
continue OUTER;
}
}
return entry.symbol;
}
}
// add new entry
Entry entry = new Entry(buffer, offset, length, fBuckets[bucket]);
fBuckets[bucket] = entry;
return entry.symbol;
} // addSymbol(char[],int,int):String
/**
* Returns a hashcode value for the specified symbol information.
* The value returned by this method must be identical to the value
* returned by the <code>hash(String)</code> method when called
* with the string object created from the symbol information.
*
* @param buffer The character buffer containing the symbol.
* @param offset The offset into the character buffer of the start
* of the symbol.
* @param length The length of the symbol.
* @return the hash value
*/
public int hash(char[] buffer, int offset, int length) {
int code = 0;
for (int i = 0; i < length; i++) {
code = code * 37 + buffer[offset + i];
}
return code & 0x7FFFFFF;
} // hash(char[],int,int):int
//
// Classes
//
/**
* This class is a symbol table entry. Each entry acts as a node
* in a linked list.
*/
private static final class Entry {
/**
* Symbol.
*/
private final String symbol;
/**
* Symbol characters. This information is duplicated here for
* comparison performance.
*/
private final char[] characters;
/**
* The next entry.
*/
private final Entry next;
/*
* Constructs a new entry from the specified symbol information and
* next entry reference.
*/
public Entry(char[] ch, int offset, int length, Entry next) {
characters = new char[length];
System.arraycopy(ch, offset, characters, 0, length);
symbol = new String(characters).intern();
this.next = next;
}
}
}

View File

@@ -0,0 +1,312 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.jasper.xmlparser;
import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
import org.apache.juli.logging.Log;
import org.apache.juli.logging.LogFactory;
/**
* Reader for UCS-2 and UCS-4 encodings.
* (i.e., encodings from ISO-10646-UCS-(2|4)).
*
* @author Neil Graham, IBM
*
* @deprecated Will be removed in Tomcat 9.0.x onwards
*/
@Deprecated
public class UCSReader extends Reader {
private final Log log = LogFactory.getLog(UCSReader.class); // must not be static
//
// Constants
//
/** Default byte buffer size (8192, larger than that of ASCIIReader
* since it's reasonable to surmise that the average UCS-4-encoded
* file should be 4 times as large as the average ASCII-encoded file).
*/
private static final int DEFAULT_BUFFER_SIZE = 8192;
public static final short UCS2LE = 1;
public static final short UCS2BE = 2;
public static final short UCS4LE = 4;
public static final short UCS4BE = 8;
//
// Data
//
/** Input stream. */
private final InputStream fInputStream;
/** Byte buffer. */
private final byte[] fBuffer;
// what kind of data we're dealing with
private final short fEncoding;
//
// Constructors
//
/**
* Constructs an ASCII reader from the specified input stream
* using the default buffer size. The Endian-ness and whether this is
* UCS-2 or UCS-4 needs also to be known in advance.
*
* @param inputStream The input stream.
* @param encoding One of UCS2LE, UCS2BE, UCS4LE or UCS4BE.
*/
public UCSReader(InputStream inputStream, short encoding) {
this(inputStream, DEFAULT_BUFFER_SIZE, encoding);
} // <init>(InputStream, short)
/**
* Constructs an ASCII reader from the specified input stream
* and buffer size. The Endian-ness and whether this is
* UCS-2 or UCS-4 needs also to be known in advance.
*
* @param inputStream The input stream.
* @param size The initial buffer size.
* @param encoding One of UCS2LE, UCS2BE, UCS4LE or UCS4BE.
*/
public UCSReader(InputStream inputStream, int size, short encoding) {
fInputStream = inputStream;
fBuffer = new byte[size];
fEncoding = encoding;
} // <init>(InputStream,int,short)
//
// Reader methods
//
/**
* Read a single character. This method will block until a character is
* available, an I/O error occurs, or the end of the stream is reached.
*
* <p> Subclasses that intend to support efficient single-character input
* should override this method.
*
* @return The character read, as an integer in the range 0 to 127
* (<code>0x00-0x7f</code>), or -1 if the end of the stream has
* been reached
*
* @exception IOException If an I/O error occurs
*/
@Override
public int read() throws IOException {
int b0 = fInputStream.read() & 0xff;
if (b0 == 0xff)
return -1;
int b1 = fInputStream.read() & 0xff;
if (b1 == 0xff)
return -1;
if(fEncoding >=4) {
int b2 = fInputStream.read() & 0xff;
if (b2 == 0xff)
return -1;
int b3 = fInputStream.read() & 0xff;
if (b3 == 0xff)
return -1;
if (log.isDebugEnabled())
log.debug("b0 is " + (b0 & 0xff) + " b1 " + (b1 & 0xff) + " b2 " + (b2 & 0xff) + " b3 " + (b3 & 0xff));
if (fEncoding == UCS4BE)
return (b0<<24)+(b1<<16)+(b2<<8)+b3;
else
return (b3<<24)+(b2<<16)+(b1<<8)+b0;
} else { // UCS-2
if (fEncoding == UCS2BE)
return (b0<<8)+b1;
else
return (b1<<8)+b0;
}
} // read():int
/**
* Read characters into a portion of an array. This method will block
* until some input is available, an I/O error occurs, or the end of the
* stream is reached.
*
* @param ch Destination buffer
* @param offset Offset at which to start storing characters
* @param length Maximum number of characters to read
*
* @return The number of characters read, or -1 if the end of the
* stream has been reached
*
* @exception IOException If an I/O error occurs
*/
@Override
public int read(char ch[], int offset, int length) throws IOException {
int byteLength = length << ((fEncoding >= 4)?2:1);
if (byteLength > fBuffer.length) {
byteLength = fBuffer.length;
}
int count = fInputStream.read(fBuffer, 0, byteLength);
if(count == -1) return -1;
// try and make count be a multiple of the number of bytes we're looking for
if(fEncoding >= 4) { // BigEndian
// this looks ugly, but it avoids an if at any rate...
int numToRead = (4 - (count & 3) & 3);
for(int i=0; i<numToRead; i++) {
int charRead = fInputStream.read();
if(charRead == -1) { // end of input; something likely went wrong!A Pad buffer with nulls.
for (int j = i;j<numToRead; j++)
fBuffer[count+j] = 0;
break;
} else {
fBuffer[count+i] = (byte)charRead;
}
}
count += numToRead;
} else {
int numToRead = count & 1;
if(numToRead != 0) {
count++;
int charRead = fInputStream.read();
if(charRead == -1) { // end of input; something likely went wrong!A Pad buffer with nulls.
fBuffer[count] = 0;
} else {
fBuffer[count] = (byte)charRead;
}
}
}
// now count is a multiple of the right number of bytes
int numChars = count >> ((fEncoding >= 4)?2:1);
int curPos = 0;
for (int i = 0; i < numChars; i++) {
int b0 = fBuffer[curPos++] & 0xff;
int b1 = fBuffer[curPos++] & 0xff;
if(fEncoding >=4) {
int b2 = fBuffer[curPos++] & 0xff;
int b3 = fBuffer[curPos++] & 0xff;
if (fEncoding == UCS4BE)
ch[offset+i] = (char)((b0<<24)+(b1<<16)+(b2<<8)+b3);
else
ch[offset+i] = (char)((b3<<24)+(b2<<16)+(b1<<8)+b0);
} else { // UCS-2
if (fEncoding == UCS2BE)
ch[offset+i] = (char)((b0<<8)+b1);
else
ch[offset+i] = (char)((b1<<8)+b0);
}
}
return numChars;
} // read(char[],int,int)
/**
* Skip characters. This method will block until some characters are
* available, an I/O error occurs, or the end of the stream is reached.
*
* @param n The number of characters to skip
*
* @return The number of characters actually skipped
*
* @exception IOException If an I/O error occurs
*/
@Override
public long skip(long n) throws IOException {
// charWidth will represent the number of bits to move
// n leftward to get num of bytes to skip, and then move the result rightward
// to get num of chars effectively skipped.
// The trick with &'ing, as with elsewhere in this dcode, is
// intended to avoid an expensive use of / that might not be optimized
// away.
int charWidth = (fEncoding >=4)?2:1;
long bytesSkipped = fInputStream.skip(n<<charWidth);
if((bytesSkipped & (charWidth | 1)) == 0) return bytesSkipped >> charWidth;
return (bytesSkipped >> charWidth) + 1;
} // skip(long):long
/**
* Tell whether this stream is ready to be read.
*
* @return True if the next read() is guaranteed not to block for input,
* false otherwise. Note that returning false does not guarantee that the
* next read will block.
*
* @exception IOException If an I/O error occurs
*/
@Override
public boolean ready() throws IOException {
return false;
} // ready()
/**
* Tell whether this stream supports the mark() operation.
*/
@Override
public boolean markSupported() {
return fInputStream.markSupported();
} // markSupported()
/**
* Mark the present position in the stream. Subsequent calls to reset()
* will attempt to reposition the stream to this point. Not all
* character-input streams support the mark() operation.
*
* @param readAheadLimit Limit on the number of characters that may be
* read while still preserving the mark. After
* reading this many characters, attempting to
* reset the stream may fail.
*
* @exception IOException If the stream does not support mark(),
* or if some other I/O error occurs
*/
@Override
public void mark(int readAheadLimit) throws IOException {
fInputStream.mark(readAheadLimit);
} // mark(int)
/**
* Reset the stream. If the stream has been marked, then attempt to
* reposition it at the mark. If the stream has not been marked, then
* attempt to reset it in some way appropriate to the particular stream,
* for example by repositioning it to its starting point. Not all
* character-input streams support the reset() operation, and some support
* reset() without supporting mark().
*
* @exception IOException If the stream has not been marked,
* or if the mark has been invalidated,
* or if the stream does not support reset(),
* or if some other I/O error occurs
*/
@Override
public void reset() throws IOException {
fInputStream.reset();
} // reset()
/**
* Close the stream. Once a stream has been closed, further read(),
* ready(), mark(), or reset() invocations will throw an IOException.
* Closing a previously-closed stream, however, has no effect.
*
* @exception IOException If an I/O error occurs
*/
@Override
public void close() throws IOException {
fInputStream.close();
} // close()
} // class UCSReader

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,161 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 1999, International
* Business Machines, Inc., http://www.apache.org. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.jasper.xmlparser;
/**
* This class is used as a structure to pass text contained in the underlying
* character buffer of the scanner. The offset and length fields allow the
* buffer to be re-used without creating new character arrays.
* <p>
* <strong>Note:</strong> Methods that are passed an XMLString structure
* should consider the contents read-only and not make any modifications
* to the contents of the buffer. The method receiving this structure
* should also not modify the offset and length if this structure (or
* the values of this structure) are passed to another method.
* <p>
* <strong>Note:</strong> Methods that are passed an XMLString structure
* are required to copy the information out of the buffer if it is to be
* saved for use beyond the scope of the method. The contents of the
* structure are volatile and the contents of the character buffer cannot
* be assured once the method that is passed this structure returns.
* Therefore, methods passed this structure should not save any reference
* to the structure or the character array contained in the structure.
*
* @author Eric Ye, IBM
* @author Andy Clark, IBM
*
* @deprecated Will be removed in Tomcat 9.0.x onwards
*/
@Deprecated
public class XMLString {
//
// Data
//
/**
* The character array.
*/
public char[] ch;
/**
* The offset into the character array.
*/
public int offset;
/**
* The length of characters from the offset.
*/
public int length;
//
// Constructors
//
/**
* Default constructor.
*/
public XMLString() {
} // <init>()
//
// Public methods
//
/**
* Initializes the contents of the XMLString structure with the
* specified values.
*
* @param ch The character array.
* @param offset The offset into the character array.
* @param length The length of characters from the offset.
*/
public void setValues(char[] ch, int offset, int length) {
this.ch = ch;
this.offset = offset;
this.length = length;
} // setValues(char[],int,int)
/**
* Initializes the contents of the XMLString structure with copies
* of the given string structure.
* <p>
* <strong>Note:</strong> This does not copy the character array;
* only the reference to the array is copied.
*
* @param s The string
*/
public void setValues(XMLString s) {
setValues(s.ch, s.offset, s.length);
} // setValues(XMLString)
/**
* Resets all of the values to their defaults.
*/
public void clear() {
this.ch = null;
this.offset = 0;
this.length = -1;
} // clear()
/**
* Returns true if the contents of this XMLString structure and
* the specified string are equal.
*
* @param s The string to compare.
* @return <code>true</code> if equal
*/
public boolean equals(String s) {
if (s == null) {
return false;
}
if ( length != s.length() ) {
return false;
}
// is this faster than call s.toCharArray first and compare the
// two arrays directly, which will possibly involve creating a
// new char array object.
for (int i=0; i<length; i++) {
if (ch[offset+i] != s.charAt(i)) {
return false;
}
}
return true;
} // equals(String):boolean
//
// Object methods
//
@Override
public String toString() {
return length > 0 ? new String(ch, offset, length) : "";
} // toString():String
} // class XMLString

View File

@@ -0,0 +1,157 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 1999, International
* Business Machines, Inc., http://www.apache.org. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.jasper.xmlparser;
/**
* 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 <strong>not</strong> modify
* the contents of the XMLString structure.
* <p>
* The contents of the string are managed by the string buffer. As
* characters are appended, the string buffer will grow as needed.
* <p>
* <strong>Note:</strong> Never set the <code>ch</code>,
* <code>offset</code>, and <code>length</code> fields directly.
* These fields are managed by the string buffer. In order to reset
* the buffer, call <code>clear()</code>.
*
* @author Andy Clark, IBM
* @author Eric Ye, IBM
*
* @deprecated Will be removed in Tomcat 9.0.x onwards
*/
@Deprecated
public class XMLStringBuffer
extends XMLString {
//
// Constants
//
/**
* Default buffer size (32).
*/
private static final int DEFAULT_SIZE = 32;
//
// Constructors
//
/**
* Build a string buffer with the default size (32).
*/
public XMLStringBuffer() {
this(DEFAULT_SIZE);
} // <init>()
/**
* Build a string buffer with the specified size.
* @param size The backing array size
*/
public XMLStringBuffer(int size) {
ch = new char[size];
} // <init>(int)
//
// Public methods
//
/**
* Clears the string buffer.
*/
@Override
public void clear() {
offset = 0;
length = 0;
}
/**
* Append character.
*
* @param c The character to append
*/
public void append(char 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++;
} // append(char)
/**
* Append string.
*
* @param s The string to append
*/
public void append(String 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;
} // append(String)
/**
* Append characters.
*
* @param ch The character array
* @param offset The offset
* @param length The length
*/
public void append(char[] ch, int offset, int 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;
} // append(char[],int,int)
/**
* Append XML string
*
* @param s The string
*/
public void append(XMLString s) {
append(s.ch, s.offset, s.length);
} // append(XMLString)
} // class XMLStringBuffer