Skip to content

Commit bc1b47b

Browse files
committed
sun.nio.cs.StreamEncoder utilizes java.lang.CharSequence.getChars
1 parent 1de94e2 commit bc1b47b

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

src/java.base/share/classes/sun/nio/cs/StreamEncoder.java

+15-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2001, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2001, 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
@@ -123,13 +123,12 @@ public void write(char[] cbuf, int off, int len) throws IOException {
123123
}
124124
}
125125

126+
public void write(CharSequence csq, int off, int len) throws IOException {
127+
implWrite(csq, off, len);
128+
}
129+
126130
public void write(String str, int off, int len) throws IOException {
127-
/* Check the len before creating a char buffer */
128-
if (len < 0)
129-
throw new IndexOutOfBoundsException();
130-
char[] cbuf = new char[len];
131-
str.getChars(off, off + len, cbuf, 0);
132-
write(cbuf, 0, len);
131+
implWrite(str, off, len);
133132
}
134133

135134
public void write(CharBuffer cb) throws IOException {
@@ -260,6 +259,15 @@ private void flushLeftoverChar(CharBuffer cb, boolean endOfInput)
260259
haveLeftoverChar = false;
261260
}
262261

262+
void implWrite(CharSequence csq, int off, int len) throws IOException {
263+
/* Check the len before creating a char buffer */
264+
if (len < 0)
265+
throw new IndexOutOfBoundsException();
266+
char[] cbuf = new char[len];
267+
csq.getChars(off, off + len, cbuf, 0);
268+
write(cbuf, 0, len);
269+
}
270+
263271
void implWrite(char[] cbuf, int off, int len)
264272
throws IOException
265273
{

0 commit comments

Comments
 (0)