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
@@ -112,24 +112,14 @@ public void write(char[] c, int off, int len) {
112
112
}
113
113
}
114
114
115
- /**
116
- * Write a portion of a string to the buffer.
117
- * @param str String to be written from
118
- * @param off Offset from which to start reading characters
119
- * @param len Number of characters to be written
120
- *
121
- * @throws IndexOutOfBoundsException
122
- * If {@code off} is negative, or {@code len} is negative,
123
- * or {@code off + len} is negative or greater than the length
124
- * of the given string
125
- */
126
- public void write (String str , int off , int len ) {
115
+ @ Override
116
+ void implWrite (CharSequence csq , int off , int len ) {
127
117
synchronized (lock ) {
128
118
int newcount = count + len ;
129
119
if (newcount > buf .length ) {
130
120
buf = Arrays .copyOf (buf , Math .max (buf .length << 1 , newcount ));
131
121
}
132
- str .getChars (off , off + len , buf , count );
122
+ csq .getChars (off , off + len , buf , count );
133
123
count = newcount ;
134
124
}
135
125
}
@@ -149,20 +139,6 @@ public void writeTo(Writer out) throws IOException {
149
139
/**
150
140
* Appends the specified character sequence to this writer.
151
141
*
152
- * <p> An invocation of this method of the form {@code out.append(csq)}
153
- * when {@code csq} is not {@code null}, behaves in exactly the same way
154
- * as the invocation
155
- *
156
- * {@snippet lang=java :
157
- * out.write(csq.toString())
158
- * }
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
142
* @param csq
167
143
* The character sequence to append. If {@code csq} is
168
144
* {@code null}, then the four characters {@code "null"} are
@@ -173,23 +149,14 @@ public void writeTo(Writer out) throws IOException {
173
149
* @since 1.5
174
150
*/
175
151
public CharArrayWriter append (CharSequence csq ) {
176
- String s = String . valueOf ( csq ) ;
177
- write ( s , 0 , s .length ());
152
+ if ( csq == null ) csq = "null" ;
153
+ implWrite ( csq , 0 , csq .length ());
178
154
return this ;
179
155
}
180
156
181
157
/**
182
158
* Appends a subsequence of the specified character sequence to this writer.
183
159
*
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
- * {@snippet lang=java :
190
- * out.write(csq.subSequence(start, end).toString())
191
- * }
192
- *
193
160
* @param csq
194
161
* The character sequence from which a subsequence will be
195
162
* appended. If {@code csq} is {@code null}, then characters
@@ -214,7 +181,8 @@ public CharArrayWriter append(CharSequence csq) {
214
181
*/
215
182
public CharArrayWriter append (CharSequence csq , int start , int end ) {
216
183
if (csq == null ) csq = "null" ;
217
- return append (csq .subSequence (start , end ));
184
+ implWrite (csq , start , end - start );
185
+ return this ;
218
186
}
219
187
220
188
/**
0 commit comments