< prev index next >

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

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


 148         }
 149     }
 150 
 151     /**
 152      * Appends the specified character sequence to this writer.
 153      *
 154      * <p> An invocation of this method of the form {@code out.append(csq)}
 155      * behaves in exactly the same way as the invocation
 156      *
 157      * <pre>
 158      *     out.write(csq.toString()) </pre>
 159      *
 160      * <p> Depending on the specification of {@code toString} for the
 161      * character sequence {@code csq}, the entire sequence may not be
 162      * appended. For instance, invoking the {@code toString} method of a
 163      * character buffer will return a subsequence whose content depends upon
 164      * the buffer's position and limit.
 165      *
 166      * @param  csq
 167      *         The character sequence to append.  If {@code csq} is
 168      *         {@code null}, then the four characters "{@code null}" are
 169      *         appended to this writer.
 170      *
 171      * @return  This writer
 172      *
 173      * @since  1.5
 174      */
 175     public CharArrayWriter append(CharSequence csq) {
 176         String s = (csq == null ? "null" : csq.toString());
 177         write(s, 0, s.length());
 178         return this;
 179     }
 180 
 181     /**
 182      * Appends a subsequence of the specified character sequence to this writer.
 183      *
 184      * <p> An invocation of this method of the form
 185      * {@code out.append(csq, start, end)} when
 186      * {@code csq} is not {@code null}, behaves in
 187      * exactly the same way as the invocation
 188      *
 189      * <pre>
 190      *     out.write(csq.subSequence(start, end).toString()) </pre>
 191      *
 192      * @param  csq
 193      *         The character sequence from which a subsequence will be
 194      *         appended.  If {@code csq} is {@code null}, then characters
 195      *         will be appended as if {@code csq} contained the four
 196      *         characters "{@code null}".
 197      *
 198      * @param  start
 199      *         The index of the first character in the subsequence
 200      *
 201      * @param  end
 202      *         The index of the character following the last character in the
 203      *         subsequence
 204      *
 205      * @return  This writer
 206      *
 207      * @throws  IndexOutOfBoundsException
 208      *          If {@code start} or {@code end} are negative, {@code start}
 209      *          is greater than {@code end}, or {@code end} is greater than
 210      *          {@code csq.length()}
 211      *
 212      * @since  1.5
 213      */
 214     public CharArrayWriter append(CharSequence csq, int start, int end) {
 215         String s = (csq == null ? "null" : csq).subSequence(start, end).toString();
 216         write(s, 0, s.length());
 217         return this;
 218     }
 219 
 220     /**
 221      * Appends the specified character to this writer.
 222      *
 223      * <p> An invocation of this method of the form {@code out.append(c)}
 224      * behaves in exactly the same way as the invocation
 225      *
 226      * <pre>
 227      *     out.write(c) </pre>
 228      *
 229      * @param  c
 230      *         The 16-bit character to append
 231      *
 232      * @return  This writer
 233      *
 234      * @since 1.5
 235      */
 236     public CharArrayWriter append(char c) {
 237         write(c);
 238         return this;
 239     }
 240 
 241     /**
 242      * Resets the buffer so that you can use it again without
 243      * throwing away the already allocated buffer.
 244      */
 245     public void reset() {
 246         count = 0;
 247     }
 248 
 249     /**
 250      * Returns a copy of the input data.
 251      *
 252      * @return an array of chars copied from the input data.
 253      */
 254     public char toCharArray()[] {
 255         synchronized (lock) {
 256             return Arrays.copyOf(buf, count);
 257         }
 258     }
 259 
 260     /**
 261      * Returns the current size of the buffer.
 262      *
 263      * @return an int representing the current size of the buffer.
 264      */
 265     public int size() {
 266         return count;
 267     }
 268 
 269     /**
 270      * Converts input data to a string.
 271      * @return the string.
 272      */
 273     public String toString() {
 274         synchronized (lock) {


 148         }
 149     }
 150 
 151     /**
 152      * Appends the specified character sequence to this writer.
 153      *
 154      * <p> An invocation of this method of the form {@code out.append(csq)}
 155      * behaves in exactly the same way as the invocation
 156      *
 157      * <pre>
 158      *     out.write(csq.toString()) </pre>
 159      *
 160      * <p> Depending on the specification of {@code toString} for the
 161      * character sequence {@code csq}, the entire sequence may not be
 162      * appended. For instance, invoking the {@code toString} method of a
 163      * character buffer will return a subsequence whose content depends upon
 164      * the buffer's position and limit.
 165      *
 166      * @param  csq
 167      *         The character sequence to append.  If {@code csq} is
 168      *         {@code null}, then the four characters {@code "null"} are
 169      *         appended to this writer.
 170      *
 171      * @return  This writer
 172      *
 173      * @since  1.5
 174      */
 175     public CharArrayWriter append(CharSequence csq) {
 176         String s = String.valueOf(csq);
 177         write(s, 0, s.length());
 178         return this;
 179     }
 180 
 181     /**
 182      * Appends a subsequence of the specified character sequence to this writer.
 183      *
 184      * <p> An invocation of this method of the form
 185      * {@code out.append(csq, start, end)} when
 186      * {@code csq} is not {@code null}, behaves in
 187      * exactly the same way as the invocation
 188      *
 189      * <pre>
 190      *     out.write(csq.subSequence(start, end).toString()) </pre>
 191      *
 192      * @param  csq
 193      *         The character sequence from which a subsequence will be
 194      *         appended.  If {@code csq} is {@code null}, then characters
 195      *         will be appended as if {@code csq} contained the four
 196      *         characters {@code "null"}.
 197      *
 198      * @param  start
 199      *         The index of the first character in the subsequence
 200      *
 201      * @param  end
 202      *         The index of the character following the last character in the
 203      *         subsequence
 204      *
 205      * @return  This writer
 206      *
 207      * @throws  IndexOutOfBoundsException
 208      *          If {@code start} or {@code end} are negative, {@code start}
 209      *          is greater than {@code end}, or {@code end} is greater than
 210      *          {@code csq.length()}
 211      *
 212      * @since  1.5
 213      */
 214     public CharArrayWriter append(CharSequence csq, int start, int end) {
 215         if (csq == null) csq = "null";
 216         return append(csq.subSequence(start, end));

 217     }
 218 
 219     /**
 220      * Appends the specified character to this writer.
 221      *
 222      * <p> An invocation of this method of the form {@code out.append(c)}
 223      * behaves in exactly the same way as the invocation
 224      *
 225      * <pre>
 226      *     out.write(c) </pre>
 227      *
 228      * @param  c
 229      *         The 16-bit character to append
 230      *
 231      * @return  This writer
 232      *
 233      * @since 1.5
 234      */
 235     public CharArrayWriter append(char c) {
 236         write(c);
 237         return this;
 238     }
 239 
 240     /**
 241      * Resets the buffer so that you can use it again without
 242      * throwing away the already allocated buffer.
 243      */
 244     public void reset() {
 245         count = 0;
 246     }
 247 
 248     /**
 249      * Returns a copy of the input data.
 250      *
 251      * @return an array of chars copied from the input data.
 252      */
 253     public char[] toCharArray() {
 254         synchronized (lock) {
 255             return Arrays.copyOf(buf, count);
 256         }
 257     }
 258 
 259     /**
 260      * Returns the current size of the buffer.
 261      *
 262      * @return an int representing the current size of the buffer.
 263      */
 264     public int size() {
 265         return count;
 266     }
 267 
 268     /**
 269      * Converts input data to a string.
 270      * @return the string.
 271      */
 272     public String toString() {
 273         synchronized (lock) {
< prev index next >