1
1
/*
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.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* This code is free software; you can redistribute it and/or modify it
@@ -275,6 +275,10 @@ public void write(String str) throws IOException {
275
275
* If an I/O error occurs
276
276
*/
277
277
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 {
278
282
synchronized (lock ) {
279
283
char cbuf [];
280
284
if (len <= WRITE_BUFFER_SIZE ) {
@@ -285,7 +289,7 @@ public void write(String str, int off, int len) throws IOException {
285
289
} else { // Don't permanently allocate very large buffers.
286
290
cbuf = new char [len ];
287
291
}
288
- str .getChars (off , (off + len ), cbuf , 0 );
292
+ csq .getChars (off , (off + len ), cbuf , 0 );
289
293
write (cbuf , 0 , len );
290
294
}
291
295
}
@@ -298,15 +302,9 @@ public void write(String str, int off, int len) throws IOException {
298
302
* as the invocation
299
303
*
300
304
* {@snippet lang=java :
301
- * out.write (csq.toString ())
305
+ * out.append (csq, 0, csq.length ())
302
306
* }
303
307
*
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.
309
- *
310
308
* @param csq
311
309
* The character sequence to append. If {@code csq} is
312
310
* {@code null}, then the four characters {@code "null"} are
@@ -320,22 +318,13 @@ public void write(String str, int off, int len) throws IOException {
320
318
* @since 1.5
321
319
*/
322
320
public Writer append (CharSequence csq ) throws IOException {
323
- write ( String . valueOf ( csq ));
321
+ append ( csq , 0 , csq . length ( ));
324
322
return this ;
325
323
}
326
324
327
325
/**
328
326
* Appends a subsequence of the specified character sequence to this writer.
329
327
*
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
- *
339
328
* @param csq
340
329
* The character sequence from which a subsequence will be
341
330
* appended. If {@code csq} is {@code null}, then characters
@@ -363,7 +352,8 @@ public Writer append(CharSequence csq) throws IOException {
363
352
*/
364
353
public Writer append (CharSequence csq , int start , int end ) throws IOException {
365
354
if (csq == null ) csq = "null" ;
366
- return append (csq .subSequence (start , end ));
355
+ implWrite (csq , start , end - start );
356
+ return this ;
367
357
}
368
358
369
359
/**
0 commit comments