Skip to content

Commit e04bb99

Browse files
committed
Draft: StreamEncoder uses CharSequence::getChars
1 parent 03837bb commit e04bb99

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,15 @@ public void write(char[] cbuf, int off, int len) throws IOException {
124124
}
125125

126126
public void write(String str, int off, int len) throws IOException {
127+
implWrite(str, off, len);
128+
}
129+
130+
private void implWrite(CharSequence csq, int off, int len) throws IOException {
127131
/* Check the len before creating a char buffer */
128132
if (len < 0)
129133
throw new IndexOutOfBoundsException();
130134
char[] cbuf = new char[len];
131-
str.getChars(off, off + len, cbuf, 0);
135+
csq.getChars(off, off + len, cbuf, 0);
132136
write(cbuf, 0, len);
133137
}
134138

@@ -144,6 +148,11 @@ public void write(CharBuffer cb) throws IOException {
144148
}
145149
}
146150

151+
public Writer append(CharSequence csq) throws IOException {
152+
implWrite(csq, 0, csq.length());
153+
return this;
154+
}
155+
147156
public void flush() throws IOException {
148157
synchronized (lock) {
149158
ensureOpen();

0 commit comments

Comments
 (0)