mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 06:45:07 +02:00
4926314: Optimize Reader.read(CharBuffer)
Reviewed-by: alanb, bpb
This commit is contained in:
parent
082abbdaf7
commit
65c19c4094
6 changed files with 371 additions and 10 deletions
|
@ -25,6 +25,7 @@
|
|||
|
||||
package java.io;
|
||||
|
||||
import java.nio.CharBuffer;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
|
@ -152,6 +153,23 @@ public class CharArrayReader extends Reader {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int read(CharBuffer target) throws IOException {
|
||||
synchronized (lock) {
|
||||
ensureOpen();
|
||||
|
||||
if (pos >= count) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
int avail = count - pos;
|
||||
int len = Math.min(avail, target.remaining());
|
||||
target.put(buf, pos, len);
|
||||
pos += len;
|
||||
return len;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Skips characters. If the stream is already at its end before this method
|
||||
* is invoked, then no characters are skipped and zero is returned.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue