Skip to content

Commit d32abc1

Browse files
committed
java.io.StringWriter utilizes java.lang.CharSequence.getChars
1 parent a1fb6d5 commit d32abc1

File tree

1 file changed

+5
-26
lines changed

1 file changed

+5
-26
lines changed

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

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
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
@@ -125,20 +125,6 @@ public void write(String str, int off, int len) {
125125
/**
126126
* Appends the specified character sequence to this writer.
127127
*
128-
* <p> An invocation of this method of the form {@code out.append(csq)}
129-
* when {@code csq} is not {@code null}, behaves in exactly the same way
130-
* as the invocation
131-
*
132-
* {@snippet lang=java :
133-
* out.write(csq.toString())
134-
* }
135-
*
136-
* <p> Depending on the specification of {@code toString} for the
137-
* character sequence {@code csq}, the entire sequence may not be
138-
* appended. For instance, invoking the {@code toString} method of a
139-
* character buffer will return a subsequence whose content depends upon
140-
* the buffer's position and limit.
141-
*
142128
* @param csq
143129
* The character sequence to append. If {@code csq} is
144130
* {@code null}, then the four characters {@code "null"} are
@@ -149,22 +135,14 @@ public void write(String str, int off, int len) {
149135
* @since 1.5
150136
*/
151137
public StringWriter append(CharSequence csq) {
152-
write(String.valueOf(csq));
138+
if (csq == null) csq = "null";
139+
buf.append(csq);
153140
return this;
154141
}
155142

156143
/**
157144
* Appends a subsequence of the specified character sequence to this writer.
158145
*
159-
* <p> An invocation of this method of the form
160-
* {@code out.append(csq, start, end)} when {@code csq}
161-
* is not {@code null}, behaves in
162-
* exactly the same way as the invocation
163-
*
164-
* {@snippet lang=java :
165-
* out.write(csq.subSequence(start, end).toString())
166-
* }
167-
*
168146
* @param csq
169147
* The character sequence from which a subsequence will be
170148
* appended. If {@code csq} is {@code null}, then characters
@@ -189,7 +167,8 @@ public StringWriter append(CharSequence csq) {
189167
*/
190168
public StringWriter append(CharSequence csq, int start, int end) {
191169
if (csq == null) csq = "null";
192-
return append(csq.subSequence(start, end));
170+
buf.append(csq, start, end);
171+
return this;
193172
}
194173

195174
/**

0 commit comments

Comments
 (0)