2362N/A * Copyright (c) 1994, 2008, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 2362N/A * published by the Free Software Foundation. Oracle designates this 0N/A * particular file as subject to the "Classpath" exception as provided 2362N/A * by Oracle in the LICENSE file that accompanied this code. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2362N/A * or visit www.oracle.com if you need additional information or have any 0N/A * A thread-safe, mutable sequence of characters. 0N/A * A string buffer is like a {@link String}, but can be modified. At any 0N/A * point in time it contains some particular sequence of characters, but 0N/A * the length and content of the sequence can be changed through certain 0N/A * String buffers are safe for use by multiple threads. The methods 0N/A * are synchronized where necessary so that all the operations on any 0N/A * particular instance behave as if they occur in some serial order 0N/A * that is consistent with the order of the method calls made by each of 0N/A * the individual threads involved. 0N/A * The principal operations on a <code>StringBuffer</code> are the 0N/A * <code>append</code> and <code>insert</code> methods, which are 0N/A * overloaded so as to accept data of any type. Each effectively 0N/A * converts a given datum to a string and then appends or inserts the 0N/A * characters of that string to the string buffer. The 0N/A * <code>append</code> method always adds these characters at the end 0N/A * of the buffer; the <code>insert</code> method adds the characters at 0N/A * a specified point. 0N/A * For example, if <code>z</code> refers to a string buffer object 0N/A * whose current contents are "<code>start</code>", then 0N/A * the method call <code>z.append("le")</code> would cause the string 0N/A * buffer to contain "<code>startle</code>", whereas 0N/A * <code>z.insert(4, "le")</code> would alter the string buffer to 0N/A * contain "<code>starlet</code>". 0N/A * In general, if sb refers to an instance of a <code>StringBuffer</code>, 0N/A * then <code>sb.append(x)</code> has the same effect as 0N/A * <code>sb.insert(sb.length(), x)</code>. 0N/A * Whenever an operation occurs involving a source sequence (such as 0N/A * appending or inserting from a source sequence) this class synchronizes 0N/A * only on the string buffer performing the operation, not on the source. 0N/A * Every string buffer has a capacity. As long as the length of the 0N/A * character sequence contained in the string buffer does not exceed 0N/A * the capacity, it is not necessary to allocate a new internal 0N/A * buffer array. If the internal buffer overflows, it is 0N/A * automatically made larger. 0N/A * As of release JDK 5, this class has been supplemented with an equivalent 0N/A * class designed for use by a single thread, {@link StringBuilder}. The 0N/A * <tt>StringBuilder</tt> class should generally be used in preference to 0N/A * this one, as it supports all of the same operations but it is faster, as 0N/A * it performs no synchronization. 0N/A * @author Arthur van Hoff 0N/A * @see java.lang.StringBuilder 0N/A * @see java.lang.String 0N/A /** use serialVersionUID from JDK 1.0.2 for interoperability */ 0N/A * Constructs a string buffer with no characters in it and an 0N/A * initial capacity of 16 characters. 0N/A * Constructs a string buffer with no characters in it and 0N/A * the specified initial capacity. 0N/A * @param capacity the initial capacity. 0N/A * @exception NegativeArraySizeException if the <code>capacity</code> 0N/A * argument is less than <code>0</code>. 0N/A * Constructs a string buffer initialized to the contents of the 0N/A * specified string. The initial capacity of the string buffer is 0N/A * <code>16</code> plus the length of the string argument. 0N/A * @param str the initial contents of the buffer. 0N/A * @exception NullPointerException if <code>str</code> is <code>null</code> 0N/A * Constructs a string buffer that contains the same characters 0N/A * as the specified <code>CharSequence</code>. The initial capacity of 0N/A * the string buffer is <code>16</code> plus the length of the 0N/A * <code>CharSequence</code> argument. 0N/A * If the length of the specified <code>CharSequence</code> is 0N/A * less than or equal to zero, then an empty buffer of capacity 0N/A * <code>16</code> is returned. 0N/A * @param seq the sequence to copy. 0N/A * @exception NullPointerException if <code>seq</code> is <code>null</code> 0N/A * @throws IndexOutOfBoundsException {@inheritDoc} 0N/A * @throws IndexOutOfBoundsException {@inheritDoc} 0N/A * @throws NullPointerException {@inheritDoc} 0N/A * @throws IndexOutOfBoundsException {@inheritDoc} 0N/A * @throws IndexOutOfBoundsException {@inheritDoc} 0N/A * Appends the specified <tt>StringBuffer</tt> to this sequence. 0N/A * The characters of the <tt>StringBuffer</tt> argument are appended, 0N/A * in order, to the contents of this <tt>StringBuffer</tt>, increasing the 0N/A * length of this <tt>StringBuffer</tt> by the length of the argument. 0N/A * If <tt>sb</tt> is <tt>null</tt>, then the four characters 0N/A * <tt>"null"</tt> are appended to this <tt>StringBuffer</tt>. 0N/A * Let <i>n</i> be the length of the old character sequence, the one 0N/A * contained in the <tt>StringBuffer</tt> just prior to execution of the 0N/A * <tt>append</tt> method. Then the character at index <i>k</i> in 0N/A * the new character sequence is equal to the character at index <i>k</i> 0N/A * in the old character sequence, if <i>k</i> is less than <i>n</i>; 0N/A * otherwise, it is equal to the character at index <i>k-n</i> in the 0N/A * argument <code>sb</code>. 0N/A * This method synchronizes on <code>this</code> (the destination) 0N/A * object but does not synchronize on the source (<code>sb</code>). 0N/A * @param sb the <tt>StringBuffer</tt> to append. 0N/A * @return a reference to this object. 0N/A * Appends the specified <code>CharSequence</code> to this 0N/A * The characters of the <code>CharSequence</code> argument are appended, 0N/A * in order, increasing the length of this sequence by the length of the 0N/A * <p>The result of this method is exactly the same as if it were an 0N/A * invocation of this.append(s, 0, s.length()); 0N/A * <p>This method synchronizes on this (the destination) 0N/A * object but does not synchronize on the source (<code>s</code>). 0N/A * <p>If <code>s</code> is <code>null</code>, then the four characters 0N/A * <code>"null"</code> are appended. 0N/A * @param s the <code>CharSequence</code> to append. 0N/A * @return a reference to this object. 0N/A // Note, synchronization achieved via other invocations 0N/A * @throws IndexOutOfBoundsException {@inheritDoc} 570N/A * @throws IndexOutOfBoundsException {@inheritDoc} 0N/A * @throws StringIndexOutOfBoundsException {@inheritDoc} 0N/A * @throws StringIndexOutOfBoundsException {@inheritDoc} 0N/A * @throws StringIndexOutOfBoundsException {@inheritDoc} 0N/A * @throws StringIndexOutOfBoundsException {@inheritDoc} 0N/A * @throws IndexOutOfBoundsException {@inheritDoc} 0N/A * @throws StringIndexOutOfBoundsException {@inheritDoc} 0N/A * @throws StringIndexOutOfBoundsException {@inheritDoc} 0N/A * @throws StringIndexOutOfBoundsException {@inheritDoc} 0N/A * @throws StringIndexOutOfBoundsException {@inheritDoc} 0N/A * @throws StringIndexOutOfBoundsException {@inheritDoc} 0N/A * @throws IndexOutOfBoundsException {@inheritDoc} 0N/A // Note, synchronization achieved via other invocations 0N/A * @throws IndexOutOfBoundsException {@inheritDoc} 0N/A * @throws StringIndexOutOfBoundsException {@inheritDoc} 0N/A * @throws IndexOutOfBoundsException {@inheritDoc} 0N/A * @throws StringIndexOutOfBoundsException {@inheritDoc} 0N/A * @throws StringIndexOutOfBoundsException {@inheritDoc} 0N/A * @throws StringIndexOutOfBoundsException {@inheritDoc} 0N/A * @throws StringIndexOutOfBoundsException {@inheritDoc} 0N/A * @throws NullPointerException {@inheritDoc} 0N/A * @throws NullPointerException {@inheritDoc} 0N/A * @throws NullPointerException {@inheritDoc} 0N/A // Note, synchronization achieved via other invocations 0N/A * @throws NullPointerException {@inheritDoc} 0N/A * Serializable fields for StringBuffer. 0N/A * @serialField value char[] 0N/A * The backing character array of this StringBuffer. 0N/A * @serialField count int 0N/A * The number of characters in this StringBuffer. 0N/A * @serialField shared boolean 0N/A * A flag indicating whether the backing array is shared. 0N/A * The value is ignored upon deserialization. 0N/A * readObject is called to restore the state of the StringBuffer from 0N/A * readObject is called to restore the state of the StringBuffer from