src/java.base/share/classes/java/io/StringWriter.java
author bpb
Thu, 06 Jun 2019 08:11:25 -0700
changeset 55259 61fff1345ee6
parent 47216 71c04702a3d5
permissions -rw-r--r--
8219992: Correct the documentation of PrintWriter to refer System.lineSeparator Reviewed-by: darcy, lancea, rriggs
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
38373
21f4f5eee7cc 8130679: Writer/StringWriter.write methods do not specify index out bounds
bpb
parents: 32033
diff changeset
     2
 * Copyright (c) 1996, 2016, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package java.io;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * A character stream that collects its output in a string buffer, which can
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * then be used to construct a string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * <p>
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 31471
diff changeset
    33
 * Closing a {@code StringWriter} has no effect. The methods in this class
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * can be called after the stream has been closed without generating an
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 31471
diff changeset
    35
 * {@code IOException}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * @author      Mark Reinhold
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 5506
diff changeset
    38
 * @since       1.1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
public class StringWriter extends Writer {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    private StringBuffer buf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
     * Create a new string writer using the default initial string-buffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
     * size.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    public StringWriter() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
        buf = new StringBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        lock = buf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
     * Create a new string writer using the specified initial string-buffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
     * size.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
     * @param initialSize
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 31471
diff changeset
    59
     *        The number of {@code char} values that will fit into this buffer
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
     *        before it is automatically expanded
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     * @throws IllegalArgumentException
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 31471
diff changeset
    63
     *         If {@code initialSize} is negative
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    public StringWriter(int initialSize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        if (initialSize < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
            throw new IllegalArgumentException("Negative buffer size");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        buf = new StringBuffer(initialSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        lock = buf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * Write a single character.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    public void write(int c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        buf.append((char) c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * Write a portion of an array of characters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * @param  cbuf  Array of characters
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * @param  off   Offset from which to start writing characters
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * @param  len   Number of characters to write
38373
21f4f5eee7cc 8130679: Writer/StringWriter.write methods do not specify index out bounds
bpb
parents: 32033
diff changeset
    86
     *
21f4f5eee7cc 8130679: Writer/StringWriter.write methods do not specify index out bounds
bpb
parents: 32033
diff changeset
    87
     * @throws  IndexOutOfBoundsException
21f4f5eee7cc 8130679: Writer/StringWriter.write methods do not specify index out bounds
bpb
parents: 32033
diff changeset
    88
     *          If {@code off} is negative, or {@code len} is negative,
21f4f5eee7cc 8130679: Writer/StringWriter.write methods do not specify index out bounds
bpb
parents: 32033
diff changeset
    89
     *          or {@code off + len} is negative or greater than the length
21f4f5eee7cc 8130679: Writer/StringWriter.write methods do not specify index out bounds
bpb
parents: 32033
diff changeset
    90
     *          of the given array
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    public void write(char cbuf[], int off, int len) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        if ((off < 0) || (off > cbuf.length) || (len < 0) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
            ((off + len) > cbuf.length) || ((off + len) < 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
            throw new IndexOutOfBoundsException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        } else if (len == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        buf.append(cbuf, off, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * Write a string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    public void write(String str) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        buf.append(str);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * Write a portion of a string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * @param  str  String to be written
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * @param  off  Offset from which to start writing characters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * @param  len  Number of characters to write
38373
21f4f5eee7cc 8130679: Writer/StringWriter.write methods do not specify index out bounds
bpb
parents: 32033
diff changeset
   115
     *
21f4f5eee7cc 8130679: Writer/StringWriter.write methods do not specify index out bounds
bpb
parents: 32033
diff changeset
   116
     * @throws  IndexOutOfBoundsException
21f4f5eee7cc 8130679: Writer/StringWriter.write methods do not specify index out bounds
bpb
parents: 32033
diff changeset
   117
     *          If {@code off} is negative, or {@code len} is negative,
21f4f5eee7cc 8130679: Writer/StringWriter.write methods do not specify index out bounds
bpb
parents: 32033
diff changeset
   118
     *          or {@code off + len} is negative or greater than the length
21f4f5eee7cc 8130679: Writer/StringWriter.write methods do not specify index out bounds
bpb
parents: 32033
diff changeset
   119
     *          of the given string
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    public void write(String str, int off, int len)  {
31471
ae27c6f1d8bf 8077242: (str) Optimize AbstractStringBuilder.append(CharSequence, int, int) for String argument
igerasim
parents: 25859
diff changeset
   122
        buf.append(str, off, off + len);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * Appends the specified character sequence to this writer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     *
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 31471
diff changeset
   128
     * <p> An invocation of this method of the form {@code out.append(csq)}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * behaves in exactly the same way as the invocation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     *     out.write(csq.toString()) </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     *
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 31471
diff changeset
   134
     * <p> Depending on the specification of {@code toString} for the
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 31471
diff changeset
   135
     * character sequence {@code csq}, the entire sequence may not be
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 31471
diff changeset
   136
     * appended. For instance, invoking the {@code toString} method of a
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * character buffer will return a subsequence whose content depends upon
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * the buffer's position and limit.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * @param  csq
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 31471
diff changeset
   141
     *         The character sequence to append.  If {@code csq} is
40410
5fd4a1f809f8 8163517: Various cleanup in java.io code
igerasim
parents: 38373
diff changeset
   142
     *         {@code null}, then the four characters {@code "null"} are
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     *         appended to this writer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * @return  This writer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * @since  1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    public StringWriter append(CharSequence csq) {
40410
5fd4a1f809f8 8163517: Various cleanup in java.io code
igerasim
parents: 38373
diff changeset
   150
        write(String.valueOf(csq));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * Appends a subsequence of the specified character sequence to this writer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     *
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 31471
diff changeset
   157
     * <p> An invocation of this method of the form
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 31471
diff changeset
   158
     * {@code out.append(csq, start, end)} when {@code csq}
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 31471
diff changeset
   159
     * is not {@code null}, behaves in
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * exactly the same way as the invocation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     *
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 31471
diff changeset
   162
     * <pre>{@code
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 31471
diff changeset
   163
     *     out.write(csq.subSequence(start, end).toString())
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 31471
diff changeset
   164
     * }</pre>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * @param  csq
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     *         The character sequence from which a subsequence will be
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 31471
diff changeset
   168
     *         appended.  If {@code csq} is {@code null}, then characters
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 31471
diff changeset
   169
     *         will be appended as if {@code csq} contained the four
40410
5fd4a1f809f8 8163517: Various cleanup in java.io code
igerasim
parents: 38373
diff changeset
   170
     *         characters {@code "null"}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * @param  start
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     *         The index of the first character in the subsequence
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * @param  end
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     *         The index of the character following the last character in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     *         subsequence
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * @return  This writer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * @throws  IndexOutOfBoundsException
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 31471
diff changeset
   182
     *          If {@code start} or {@code end} are negative, {@code start}
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 31471
diff changeset
   183
     *          is greater than {@code end}, or {@code end} is greater than
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 31471
diff changeset
   184
     *          {@code csq.length()}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * @since  1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    public StringWriter append(CharSequence csq, int start, int end) {
40410
5fd4a1f809f8 8163517: Various cleanup in java.io code
igerasim
parents: 38373
diff changeset
   189
        if (csq == null) csq = "null";
5fd4a1f809f8 8163517: Various cleanup in java.io code
igerasim
parents: 38373
diff changeset
   190
        return append(csq.subSequence(start, end));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * Appends the specified character to this writer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     *
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 31471
diff changeset
   196
     * <p> An invocation of this method of the form {@code out.append(c)}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * behaves in exactly the same way as the invocation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     *     out.write(c) </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * @param  c
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     *         The 16-bit character to append
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * @return  This writer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    public StringWriter append(char c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        write(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * Return the buffer's current value as a string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        return buf.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * Return the string buffer itself.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * @return StringBuffer holding the current buffer value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    public StringBuffer getBuffer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        return buf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * Flush the stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    public void flush() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    /**
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 31471
diff changeset
   237
     * Closing a {@code StringWriter} has no effect. The methods in this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * class can be called after the stream has been closed without generating
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 31471
diff changeset
   239
     * an {@code IOException}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    public void close() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
}