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
@@ -1049,15 +1049,9 @@ public PrintWriter format(Locale l, String format, Object ... args) {
1049
1049
* as the invocation
1050
1050
*
1051
1051
* {@snippet lang=java :
1052
- * out.write (csq.toString ())
1052
+ * out.append (csq, 0, csq.length ())
1053
1053
* }
1054
1054
*
1055
- * <p> Depending on the specification of {@code toString} for the
1056
- * character sequence {@code csq}, the entire sequence may not be
1057
- * appended. For instance, invoking the {@code toString} method of a
1058
- * character buffer will return a subsequence whose content depends upon
1059
- * the buffer's position and limit.
1060
- *
1061
1055
* @param csq
1062
1056
* The character sequence to append. If {@code csq} is
1063
1057
* {@code null}, then the four characters {@code "null"} are
@@ -1068,22 +1062,12 @@ public PrintWriter format(Locale l, String format, Object ... args) {
1068
1062
* @since 1.5
1069
1063
*/
1070
1064
public PrintWriter append (CharSequence csq ) {
1071
- write (String .valueOf (csq ));
1072
- return this ;
1065
+ return append (csq , 0 , csq .length ());
1073
1066
}
1074
1067
1075
1068
/**
1076
1069
* Appends a subsequence of the specified character sequence to this writer.
1077
1070
*
1078
- * <p> An invocation of this method of the form
1079
- * {@code out.append(csq, start, end)}
1080
- * when {@code csq} is not {@code null}, behaves in
1081
- * exactly the same way as the invocation
1082
- *
1083
- * {@snippet lang=java :
1084
- * out.write(csq.subSequence(start, end).toString())
1085
- * }
1086
- *
1087
1071
* @param csq
1088
1072
* The character sequence from which a subsequence will be
1089
1073
* appended. If {@code csq} is {@code null}, then characters
@@ -1108,7 +1092,17 @@ public PrintWriter append(CharSequence csq) {
1108
1092
*/
1109
1093
public PrintWriter append (CharSequence csq , int start , int end ) {
1110
1094
if (csq == null ) csq = "null" ;
1111
- return append (csq .subSequence (start , end ));
1095
+ synchronized (lock ) {
1096
+ try {
1097
+ ensureOpen ();
1098
+ out .append (csq , start , end );
1099
+ } catch (InterruptedIOException x ) {
1100
+ Thread .currentThread ().interrupt ();
1101
+ } catch (IOException x ) {
1102
+ trouble = true ;
1103
+ }
1104
+ }
1105
+ return this ;
1112
1106
}
1113
1107
1114
1108
/**
0 commit comments