< prev index next >

src/java.base/share/classes/java/io/StringWriter.java

Print this page
rev 15365 : imported patch 8163517-Various-cleanup-in-java-io-code


 122         buf.append(str, off, off + len);
 123     }
 124 
 125     /**
 126      * Appends the specified character sequence to this writer.
 127      *
 128      * <p> An invocation of this method of the form {@code out.append(csq)}
 129      * behaves in exactly the same way as the invocation
 130      *
 131      * <pre>
 132      *     out.write(csq.toString()) </pre>
 133      *
 134      * <p> Depending on the specification of {@code toString} for the
 135      * character sequence {@code csq}, the entire sequence may not be
 136      * appended. For instance, invoking the {@code toString} method of a
 137      * character buffer will return a subsequence whose content depends upon
 138      * the buffer's position and limit.
 139      *
 140      * @param  csq
 141      *         The character sequence to append.  If {@code csq} is
 142      *         {@code null}, then the four characters "{@code null}" are
 143      *         appended to this writer.
 144      *
 145      * @return  This writer
 146      *
 147      * @since  1.5
 148      */
 149     public StringWriter append(CharSequence csq) {
 150         if (csq == null)
 151             write("null");
 152         else
 153             write(csq.toString());
 154         return this;
 155     }
 156 
 157     /**
 158      * Appends a subsequence of the specified character sequence to this writer.
 159      *
 160      * <p> An invocation of this method of the form
 161      * {@code out.append(csq, start, end)} when {@code csq}
 162      * is not {@code null}, behaves in
 163      * exactly the same way as the invocation
 164      *
 165      * <pre>{@code
 166      *     out.write(csq.subSequence(start, end).toString())
 167      * }</pre>
 168      *
 169      * @param  csq
 170      *         The character sequence from which a subsequence will be
 171      *         appended.  If {@code csq} is {@code null}, then characters
 172      *         will be appended as if {@code csq} contained the four
 173      *         characters "{@code null}".
 174      *
 175      * @param  start
 176      *         The index of the first character in the subsequence
 177      *
 178      * @param  end
 179      *         The index of the character following the last character in the
 180      *         subsequence
 181      *
 182      * @return  This writer
 183      *
 184      * @throws  IndexOutOfBoundsException
 185      *          If {@code start} or {@code end} are negative, {@code start}
 186      *          is greater than {@code end}, or {@code end} is greater than
 187      *          {@code csq.length()}
 188      *
 189      * @since  1.5
 190      */
 191     public StringWriter append(CharSequence csq, int start, int end) {
 192         CharSequence cs = (csq == null ? "null" : csq);
 193         write(cs.subSequence(start, end).toString());
 194         return this;
 195     }
 196 
 197     /**
 198      * Appends the specified character to this writer.
 199      *
 200      * <p> An invocation of this method of the form {@code out.append(c)}
 201      * behaves in exactly the same way as the invocation
 202      *
 203      * <pre>
 204      *     out.write(c) </pre>
 205      *
 206      * @param  c
 207      *         The 16-bit character to append
 208      *
 209      * @return  This writer
 210      *
 211      * @since 1.5
 212      */
 213     public StringWriter append(char c) {
 214         write(c);




 122         buf.append(str, off, off + len);
 123     }
 124 
 125     /**
 126      * Appends the specified character sequence to this writer.
 127      *
 128      * <p> An invocation of this method of the form {@code out.append(csq)}
 129      * behaves in exactly the same way as the invocation
 130      *
 131      * <pre>
 132      *     out.write(csq.toString()) </pre>
 133      *
 134      * <p> Depending on the specification of {@code toString} for the
 135      * character sequence {@code csq}, the entire sequence may not be
 136      * appended. For instance, invoking the {@code toString} method of a
 137      * character buffer will return a subsequence whose content depends upon
 138      * the buffer's position and limit.
 139      *
 140      * @param  csq
 141      *         The character sequence to append.  If {@code csq} is
 142      *         {@code null}, then the four characters {@code "null"} are
 143      *         appended to this writer.
 144      *
 145      * @return  This writer
 146      *
 147      * @since  1.5
 148      */
 149     public StringWriter append(CharSequence csq) {
 150         write(String.valueOf(csq));



 151         return this;
 152     }
 153 
 154     /**
 155      * Appends a subsequence of the specified character sequence to this writer.
 156      *
 157      * <p> An invocation of this method of the form
 158      * {@code out.append(csq, start, end)} when {@code csq}
 159      * is not {@code null}, behaves in
 160      * exactly the same way as the invocation
 161      *
 162      * <pre>{@code
 163      *     out.write(csq.subSequence(start, end).toString())
 164      * }</pre>
 165      *
 166      * @param  csq
 167      *         The character sequence from which a subsequence will be
 168      *         appended.  If {@code csq} is {@code null}, then characters
 169      *         will be appended as if {@code csq} contained the four
 170      *         characters {@code "null"}.
 171      *
 172      * @param  start
 173      *         The index of the first character in the subsequence
 174      *
 175      * @param  end
 176      *         The index of the character following the last character in the
 177      *         subsequence
 178      *
 179      * @return  This writer
 180      *
 181      * @throws  IndexOutOfBoundsException
 182      *          If {@code start} or {@code end} are negative, {@code start}
 183      *          is greater than {@code end}, or {@code end} is greater than
 184      *          {@code csq.length()}
 185      *
 186      * @since  1.5
 187      */
 188     public StringWriter append(CharSequence csq, int start, int end) {
 189         if (csq == null) csq = "null";
 190         return append(csq.subSequence(start, end));

 191     }
 192 
 193     /**
 194      * Appends the specified character to this writer.
 195      *
 196      * <p> An invocation of this method of the form {@code out.append(c)}
 197      * behaves in exactly the same way as the invocation
 198      *
 199      * <pre>
 200      *     out.write(c) </pre>
 201      *
 202      * @param  c
 203      *         The 16-bit character to append
 204      *
 205      * @return  This writer
 206      *
 207      * @since 1.5
 208      */
 209     public StringWriter append(char c) {
 210         write(c);


< prev index next >