11/*
2- * Copyright (c) 1996, 2024 , Oracle and/or its affiliates. All rights reserved.
2+ * Copyright (c) 1996, 2025 , Oracle and/or its affiliates. All rights reserved.
33 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44 *
55 * This code is free software; you can redistribute it and/or modify it
@@ -275,6 +275,10 @@ public void write(String str) throws IOException {
275275 * If an I/O error occurs
276276 */
277277 public void write (String str , int off , int len ) throws IOException {
278+ implWrite (str , off , len );
279+ }
280+
281+ void implWrite (CharSequence csq , int off , int len ) throws IOException {
278282 synchronized (lock ) {
279283 char cbuf [];
280284 if (len <= WRITE_BUFFER_SIZE ) {
@@ -285,27 +289,20 @@ public void write(String str, int off, int len) throws IOException {
285289 } else { // Don't permanently allocate very large buffers.
286290 cbuf = new char [len ];
287291 }
288- str .getChars (off , (off + len ), cbuf , 0 );
292+ csq .getChars (off , (off + len ), cbuf , 0 );
289293 write (cbuf , 0 , len );
290294 }
291295 }
292296
293297 /**
294298 * Appends the specified character sequence to this writer.
295299 *
296- * <p> An invocation of this method of the form {@code out.append(csq)}
297- * when {@code csq} is not {@code null}, behaves in exactly the same way
298- * as the invocation
299- *
300- * {@snippet lang=java :
301- * out.write(csq.toString())
302- * }
300+ * @implSpec The default implemenation behaves in exactly the same way as
301+ * the invocation
303302 *
304- * <p> Depending on the specification of {@code toString} for the
305- * character sequence {@code csq}, the entire sequence may not be
306- * appended. For instance, invoking the {@code toString} method of a
307- * character buffer will return a subsequence whose content depends upon
308- * the buffer's position and limit.
303+ * {@snippet lang=java :
304+ * return append(csq, 0, csq.length());
305+ * }
309306 *
310307 * @param csq
311308 * The character sequence to append. If {@code csq} is
@@ -320,22 +317,12 @@ public void write(String str, int off, int len) throws IOException {
320317 * @since 1.5
321318 */
322319 public Writer append (CharSequence csq ) throws IOException {
323- write (String .valueOf (csq ));
324- return this ;
320+ return append (csq , 0 , csq .length ());
325321 }
326322
327323 /**
328324 * Appends a subsequence of the specified character sequence to this writer.
329325 *
330- * <p> An invocation of this method of the form
331- * {@code out.append(csq, start, end)} when {@code csq}
332- * is not {@code null} behaves in exactly the
333- * same way as the invocation
334- *
335- * {@snippet lang=java :
336- * out.write(csq.subSequence(start, end).toString())
337- * }
338- *
339326 * @param csq
340327 * The character sequence from which a subsequence will be
341328 * appended. If {@code csq} is {@code null}, then characters
@@ -363,7 +350,8 @@ public Writer append(CharSequence csq) throws IOException {
363350 */
364351 public Writer append (CharSequence csq , int start , int end ) throws IOException {
365352 if (csq == null ) csq = "null" ;
366- return append (csq .subSequence (start , end ));
353+ implWrite (csq , start , end - start );
354+ return this ;
367355 }
368356
369357 /**
0 commit comments