Skip to content

Commit e159d63

Browse files
committed
java.io.PrintWriter utilizes java.lang.CharSequence.getChars
1 parent d32abc1 commit e159d63

File tree

1 file changed

+14
-20
lines changed

1 file changed

+14
-20
lines changed

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

Lines changed: 14 additions & 20 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
@@ -1049,15 +1049,9 @@ public PrintWriter format(Locale l, String format, Object ... args) {
10491049
* as the invocation
10501050
*
10511051
* {@snippet lang=java :
1052-
* out.write(csq.toString())
1052+
* out.append(csq, 0, csq.length())
10531053
* }
10541054
*
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-
*
10611055
* @param csq
10621056
* The character sequence to append. If {@code csq} is
10631057
* {@code null}, then the four characters {@code "null"} are
@@ -1068,22 +1062,12 @@ public PrintWriter format(Locale l, String format, Object ... args) {
10681062
* @since 1.5
10691063
*/
10701064
public PrintWriter append(CharSequence csq) {
1071-
write(String.valueOf(csq));
1072-
return this;
1065+
return append(csq, 0, csq.length());
10731066
}
10741067

10751068
/**
10761069
* Appends a subsequence of the specified character sequence to this writer.
10771070
*
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-
*
10871071
* @param csq
10881072
* The character sequence from which a subsequence will be
10891073
* appended. If {@code csq} is {@code null}, then characters
@@ -1108,7 +1092,17 @@ public PrintWriter append(CharSequence csq) {
11081092
*/
11091093
public PrintWriter append(CharSequence csq, int start, int end) {
11101094
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;
11121106
}
11131107

11141108
/**

0 commit comments

Comments
 (0)