1 7 8 package java.lang; 9 10 import sun.misc.FloatingDecimal; 11 12 67 public final class StringBuffer 68 extends AbstractStringBuilder 69 implements java.io.Serializable , CharSequence 70 { 71 72 73 static final long serialVersionUID = 3388685877147921107L; 74 75 79 public StringBuffer() { 80 super(16); 81 } 82 83 91 public StringBuffer(int capacity) { 92 super(capacity); 93 } 94 95 103 public StringBuffer(String str) { 104 super(str.length() + 16); 105 append(str); 106 } 107 108 122 public StringBuffer(CharSequence seq) { 123 this(seq.length() + 16); 124 append(seq); 125 } 126 127 public synchronized int length() { 128 return count; 129 } 130 131 public synchronized int capacity() { 132 return value.length; 133 } 134 135 136 public synchronized void ensureCapacity(int minimumCapacity) { 137 if (minimumCapacity > value.length) { 138 expandCapacity(minimumCapacity); 139 } 140 } 141 142 145 public synchronized void trimToSize() { 146 super.trimToSize(); 147 } 148 149 153 public synchronized void setLength(int newLength) { 154 super.setLength(newLength); 155 } 156 157 161 public synchronized char charAt(int index) { 162 if ((index < 0) || (index >= count)) 163 throw new StringIndexOutOfBoundsException (index); 164 return value[index]; 165 } 166 167 170 public synchronized int codePointAt(int index) { 171 return super.codePointAt(index); 172 } 173 174 177 public synchronized int codePointBefore(int index) { 178 return super.codePointBefore(index); 179 } 180 181 184 public synchronized int codePointCount(int beginIndex, int endIndex) { 185 return super.codePointCount(beginIndex, endIndex); 186 } 187 188 191 public synchronized int offsetByCodePoints(int index, int codePointOffset) { 192 return super.offsetByCodePoints(index, codePointOffset); 193 } 194 195 199 public synchronized void getChars(int srcBegin, int srcEnd, char dst[], 200 int dstBegin) 201 { 202 super.getChars(srcBegin, srcEnd, dst, dstBegin); 203 } 204 205 209 public synchronized void setCharAt(int index, char ch) { 210 if ((index < 0) || (index >= count)) 211 throw new StringIndexOutOfBoundsException (index); 212 value[index] = ch; 213 } 214 215 219 public synchronized StringBuffer append(Object obj) { 220 super.append(String.valueOf(obj)); 221 return this; 222 } 223 224 public synchronized StringBuffer append(String str) { 225 super.append(str); 226 return this; 227 } 228 229 253 public synchronized StringBuffer append(StringBuffer sb) { 254 super.append(sb); 255 return this; 256 } 257 258 259 280 public StringBuffer append(CharSequence s) { 281 if (s == null) 283 s = "null"; 284 if (s instanceof String ) 285 return this.append((String )s); 286 if (s instanceof StringBuffer ) 287 return this.append((StringBuffer )s); 288 return this.append(s, 0, s.length()); 289 } 290 291 295 public synchronized StringBuffer append(CharSequence s, int start, int end) 296 { 297 super.append(s, start, end); 298 return this; 299 } 300 301 public synchronized StringBuffer append(char str[]) { 302 super.append(str); 303 return this; 304 } 305 306 public synchronized StringBuffer append(char str[], int offset, int len) { 307 super.append(str, offset, len); 308 return this; 309 } 310 311 315 public synchronized StringBuffer append(boolean b) { 316 super.append(b); 317 return this; 318 } 319 320 public synchronized StringBuffer append(char c) { 321 super.append(c); 322 return this; 323 } 324 325 329 public synchronized StringBuffer append(int i) { 330 super.append(i); 331 return this; 332 } 333 334 337 public synchronized StringBuffer appendCodePoint(int codePoint) { 338 super.appendCodePoint(codePoint); 339 return this; 340 } 341 342 346 public synchronized StringBuffer append(long lng) { 347 super.append(lng); 348 return this; 349 } 350 351 355 public synchronized StringBuffer append(float f) { 356 new FloatingDecimal(f).appendTo(this); 357 return this; 358 } 359 360 364 public synchronized StringBuffer append(double d) { 365 new FloatingDecimal(d).appendTo(this); 366 return this; 367 } 368 369 373 public synchronized StringBuffer delete(int start, int end) { 374 super.delete(start, end); 375 return this; 376 } 377 378 382 public synchronized StringBuffer deleteCharAt(int index) { 383 super.deleteCharAt(index); 384 return this; 385 } 386 387 391 public synchronized StringBuffer replace(int start, int end, String str) { 392 super.replace(start, end, str); 393 return this; 394 } 395 396 400 public synchronized String substring(int start) { 401 return substring(start, count); 402 } 403 404 408 public synchronized CharSequence subSequence(int start, int end) { 409 return super.substring(start, end); 410 } 411 412 416 public synchronized String substring(int start, int end) { 417 return super.substring(start, end); 418 } 419 420 424 public synchronized StringBuffer insert(int index, char str[], int offset, 425 int len) 426 { 427 super.insert(index, str, offset, len); 428 return this; 429 } 430 431 437 public synchronized StringBuffer insert(int offset, Object obj) { 438 super.insert(offset, String.valueOf(obj)); 439 return this; 440 } 441 442 446 public synchronized StringBuffer insert(int offset, String str) { 447 super.insert(offset, str); 448 return this; 449 } 450 451 454 public synchronized StringBuffer insert(int offset, char str[]) { 455 super.insert(offset, str); 456 return this; 457 } 458 459 463 public StringBuffer insert(int dstOffset, CharSequence s) { 464 if (s == null) 466 s = "null"; 467 if (s instanceof String ) 468 return this.insert(dstOffset, (String )s); 469 return this.insert(dstOffset, s, 0, s.length()); 470 } 471 472 476 public synchronized StringBuffer insert(int dstOffset, CharSequence s, 477 int start, int end) 478 { 479 super.insert(dstOffset, s, start, end); 480 return this; 481 } 482 483 489 public StringBuffer insert(int offset, boolean b) { 490 return insert(offset, String.valueOf(b)); 491 } 492 493 497 public synchronized StringBuffer insert(int offset, char c) { 498 super.insert(offset, c); 499 return this; 500 } 501 502 508 public StringBuffer insert(int offset, int i) { 509 return insert(offset, String.valueOf(i)); 510 } 511 512 518 public StringBuffer insert(int offset, long l) { 519 return insert(offset, String.valueOf(l)); 520 } 521 522 528 public StringBuffer insert(int offset, float f) { 529 return insert(offset, String.valueOf(f)); 530 } 531 532 538 public StringBuffer insert(int offset, double d) { 539 return insert(offset, String.valueOf(d)); 540 } 541 542 546 public int indexOf(String str) { 547 return indexOf(str, 0); 548 } 549 550 554 public synchronized int indexOf(String str, int fromIndex) { 555 return String.indexOf(value, 0, count, 556 str.toCharArray(), 0, str.length(), fromIndex); 557 } 558 559 563 public int lastIndexOf(String str) { 564 return lastIndexOf(str, count); 566 } 567 568 572 public synchronized int lastIndexOf(String str, int fromIndex) { 573 return String.lastIndexOf(value, 0, count, 574 str.toCharArray(), 0, str.length(), fromIndex); 575 } 576 577 580 public synchronized StringBuffer reverse() { 581 super.reverse(); 582 return this; 583 } 584 585 public synchronized String toString() { 586 return new String (value, 0, count); 587 } 588 589 600 private static final java.io.ObjectStreamField [] serialPersistentFields = 601 { 602 new java.io.ObjectStreamField ("value", char[].class), 603 new java.io.ObjectStreamField ("count", Integer.TYPE), 604 new java.io.ObjectStreamField ("shared", Boolean.TYPE), 605 }; 606 607 611 private synchronized void writeObject(java.io.ObjectOutputStream s) 612 throws java.io.IOException { 613 java.io.ObjectOutputStream.PutField fields = s.putFields(); 614 fields.put("value", value); 615 fields.put("count", count); 616 fields.put("shared", false); 617 s.writeFields(); 618 } 619 620 624 private void readObject(java.io.ObjectInputStream s) 625 throws java.io.IOException , ClassNotFoundException { 626 java.io.ObjectInputStream.GetField fields = s.readFields(); 627 value = (char[])fields.get("value", null); 628 count = (int)fields.get("count", 0); 629 } 630 } 631 | Popular Tags |