src/java.base/share/classes/java/lang/StringBuffer.java
Print this page
*** 102,112 ****
/**
* A cache of the last value returned by toString. Cleared
* whenever the StringBuffer is modified.
*/
! private transient char[] toStringCache;
/** use serialVersionUID from JDK 1.0.2 for interoperability */
static final long serialVersionUID = 3388685877147921107L;
/**
--- 102,112 ----
/**
* A cache of the last value returned by toString. Cleared
* whenever the StringBuffer is modified.
*/
! private transient String toStringCache;
/** use serialVersionUID from JDK 1.0.2 for interoperability */
static final long serialVersionUID = 3388685877147921107L;
/**
*** 167,185 ****
return count;
}
@Override
public synchronized int capacity() {
! return value.length;
}
@Override
public synchronized void ensureCapacity(int minimumCapacity) {
! if (minimumCapacity > value.length) {
! expandCapacity(minimumCapacity);
! }
}
/**
* @since 1.5
*/
--- 167,183 ----
return count;
}
@Override
public synchronized int capacity() {
! return super.capacity();
}
@Override
public synchronized void ensureCapacity(int minimumCapacity) {
! super.ensureCapacity(minimumCapacity);
}
/**
* @since 1.5
*/
*** 202,214 ****
* @throws IndexOutOfBoundsException {@inheritDoc}
* @see #length()
*/
@Override
public synchronized char charAt(int index) {
! if ((index < 0) || (index >= count))
! throw new StringIndexOutOfBoundsException(index);
! return value[index];
}
/**
* @throws IndexOutOfBoundsException {@inheritDoc}
* @since 1.5
--- 200,210 ----
* @throws IndexOutOfBoundsException {@inheritDoc}
* @see #length()
*/
@Override
public synchronized char charAt(int index) {
! return super.charAt(index);
}
/**
* @throws IndexOutOfBoundsException {@inheritDoc}
* @since 1.5
*** 259,272 ****
* @throws IndexOutOfBoundsException {@inheritDoc}
* @see #length()
*/
@Override
public synchronized void setCharAt(int index, char ch) {
- if ((index < 0) || (index >= count))
- throw new StringIndexOutOfBoundsException(index);
toStringCache = null;
! value[index] = ch;
}
@Override
public synchronized StringBuffer append(Object obj) {
toStringCache = null;
--- 255,266 ----
* @throws IndexOutOfBoundsException {@inheritDoc}
* @see #length()
*/
@Override
public synchronized void setCharAt(int index, char ch) {
toStringCache = null;
! super.setCharAt(index, ch);
}
@Override
public synchronized StringBuffer append(Object obj) {
toStringCache = null;
*** 678,690 ****
@Override
@HotSpotIntrinsicCandidate
public synchronized String toString() {
if (toStringCache == null) {
! toStringCache = Arrays.copyOfRange(value, 0, count);
}
! return new String(toStringCache, true);
}
/**
* Serializable fields for StringBuffer.
*
--- 672,686 ----
@Override
@HotSpotIntrinsicCandidate
public synchronized String toString() {
if (toStringCache == null) {
! return toStringCache =
! isLatin1() ? StringLatin1.newString(value, 0, count)
! : StringUTF16.newString(value, 0, count);
}
! return new String(toStringCache);
}
/**
* Serializable fields for StringBuffer.
*
*** 708,718 ****
* a stream.
*/
private synchronized void writeObject(java.io.ObjectOutputStream s)
throws java.io.IOException {
java.io.ObjectOutputStream.PutField fields = s.putFields();
! fields.put("value", value);
fields.put("count", count);
fields.put("shared", false);
s.writeFields();
}
--- 704,720 ----
* a stream.
*/
private synchronized void writeObject(java.io.ObjectOutputStream s)
throws java.io.IOException {
java.io.ObjectOutputStream.PutField fields = s.putFields();
! char[] val = new char[capacity()];
! if (isLatin1()) {
! StringLatin1.getChars(value, 0, count, val, 0);
! } else {
! StringUTF16.getChars(value, 0, count, val, 0);
! }
! fields.put("value", val);
fields.put("count", count);
fields.put("shared", false);
s.writeFields();
}
*** 721,729 ****
* a stream.
*/
private void readObject(java.io.ObjectInputStream s)
throws java.io.IOException, ClassNotFoundException {
java.io.ObjectInputStream.GetField fields = s.readFields();
! value = (char[])fields.get("value", null);
count = fields.get("count", 0);
}
}
--- 723,736 ----
* a stream.
*/
private void readObject(java.io.ObjectInputStream s)
throws java.io.IOException, ClassNotFoundException {
java.io.ObjectInputStream.GetField fields = s.readFields();
! char[] val = (char[])fields.get("value", null);
! initBytes(val, 0, val.length);
count = fields.get("count", 0);
}
+
+ protected synchronized void getBytes(byte dst[], int dstBegin, byte coder) {
+ super.getBytes(dst, dstBegin, coder);
+ }
}