< prev index next >

src/java.base/share/classes/java/lang/StringBuilder.java

Print this page
rev 13124 : [mq]: XXXXXXX-ASB-shared-value


 394 
 395     @Override
 396     public int lastIndexOf(String str) {
 397         return super.lastIndexOf(str);
 398     }
 399 
 400     @Override
 401     public int lastIndexOf(String str, int fromIndex) {
 402         return super.lastIndexOf(str, fromIndex);
 403     }
 404 
 405     @Override
 406     public StringBuilder reverse() {
 407         super.reverse();
 408         return this;
 409     }
 410 
 411     @Override
 412     @HotSpotIntrinsicCandidate
 413     public String toString() {
 414         // Create a copy, don't share the array
 415         return isLatin1() ? StringLatin1.newString(value, 0, count)
 416                           : StringUTF16.newStringSB(value, 0, count);






 417     }
 418 
 419     /**
 420      * Save the state of the {@code StringBuilder} instance to a stream
 421      * (that is, serialize it).
 422      *
 423      * @serialData the number of characters currently stored in the string
 424      *             builder ({@code int}), followed by the characters in the
 425      *             string builder ({@code char[]}).   The length of the
 426      *             {@code char} array may be greater than the number of
 427      *             characters currently stored in the string builder, in which
 428      *             case extra characters are ignored.
 429      */
 430     private void writeObject(java.io.ObjectOutputStream s)
 431         throws java.io.IOException {
 432         s.defaultWriteObject();
 433         s.writeInt(count);
 434         char[] val = new char[capacity()];
 435         if (isLatin1()) {
 436             StringLatin1.getChars(value, 0, count, val, 0);
 437         } else {
 438             StringUTF16.getChars(value, 0, count, val, 0);
 439         }
 440         s.writeObject(val);
 441     }
 442 
 443     /**
 444      * readObject is called to restore the state of the StringBuffer from
 445      * a stream.
 446      */
 447     private void readObject(java.io.ObjectInputStream s)
 448         throws java.io.IOException, ClassNotFoundException {
 449         s.defaultReadObject();
 450         count = s.readInt();
 451         char[] val = (char[]) s.readObject();
 452         initBytes(val, 0, val.length);

 453     }
 454 
 455 }


 394 
 395     @Override
 396     public int lastIndexOf(String str) {
 397         return super.lastIndexOf(str);
 398     }
 399 
 400     @Override
 401     public int lastIndexOf(String str, int fromIndex) {
 402         return super.lastIndexOf(str, fromIndex);
 403     }
 404 
 405     @Override
 406     public StringBuilder reverse() {
 407         super.reverse();
 408         return this;
 409     }
 410 
 411     @Override
 412     @HotSpotIntrinsicCandidate
 413     public String toString() {
 414         final byte[] value = this.value;
 415         if (isLatin1()) {
 416             if ((count << coder) < value.length) {
 417                 return StringLatin1.newString(value, 0, count);
 418             }
 419             shared = true;
 420             return new String(value, String.LATIN1);
 421         }
 422         return StringUTF16.newStringSB(value, 0, count);
 423     }
 424 
 425     /**
 426      * Save the state of the {@code StringBuilder} instance to a stream
 427      * (that is, serialize it).
 428      *
 429      * @serialData the number of characters currently stored in the string
 430      *             builder ({@code int}), followed by the characters in the
 431      *             string builder ({@code char[]}).   The length of the
 432      *             {@code char} array may be greater than the number of
 433      *             characters currently stored in the string builder, in which
 434      *             case extra characters are ignored.
 435      */
 436     private void writeObject(java.io.ObjectOutputStream s)
 437         throws java.io.IOException {
 438         s.defaultWriteObject();
 439         s.writeInt(count);
 440         char[] val = new char[capacity()];
 441         if (isLatin1()) {
 442             StringLatin1.getChars(value, 0, count, val, 0);
 443         } else {
 444             StringUTF16.getChars(value, 0, count, val, 0);
 445         }
 446         s.writeObject(val);
 447     }
 448 
 449     /**
 450      * readObject is called to restore the state of the StringBuffer from
 451      * a stream.
 452      */
 453     private void readObject(java.io.ObjectInputStream s)
 454         throws java.io.IOException, ClassNotFoundException {
 455         s.defaultReadObject();
 456         count = s.readInt();
 457         char[] val = (char[]) s.readObject();
 458         initBytes(val, 0, val.length);
 459         shared = false;
 460     }
 461 
 462 }
< prev index next >