mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 07:14:30 +02:00
8276779: (ch) InputStream returned by Channels.newInputStream should have fast path for SelectableChannels
Reviewed-by: lancea, alanb
This commit is contained in:
parent
02ee337ae0
commit
9642629d15
3 changed files with 110 additions and 11 deletions
|
@ -34,6 +34,7 @@ import java.nio.channels.IllegalBlockingModeException;
|
|||
import java.nio.channels.ReadableByteChannel;
|
||||
import java.nio.channels.SeekableByteChannel;
|
||||
import java.nio.channels.SelectableChannel;
|
||||
import java.nio.channels.WritableByteChannel;
|
||||
import java.util.Arrays;
|
||||
import java.util.Objects;
|
||||
import jdk.internal.util.ArraysSupport;
|
||||
|
@ -238,15 +239,28 @@ public class ChannelInputStream
|
|||
Objects.requireNonNull(out, "out");
|
||||
|
||||
if (out instanceof ChannelOutputStream cos
|
||||
&& ch instanceof FileChannel fc
|
||||
&& cos.channel() instanceof FileChannel dst) {
|
||||
return transfer(fc, dst);
|
||||
&& ch instanceof FileChannel fc) {
|
||||
WritableByteChannel wbc = cos.channel();
|
||||
|
||||
if (wbc instanceof FileChannel dst) {
|
||||
return transfer(fc, dst);
|
||||
}
|
||||
|
||||
if (wbc instanceof SelectableChannel sc) {
|
||||
synchronized (sc.blockingLock()) {
|
||||
if (!sc.isBlocking())
|
||||
throw new IllegalBlockingModeException();
|
||||
return transfer(fc, wbc);
|
||||
}
|
||||
}
|
||||
|
||||
return transfer(fc, wbc);
|
||||
}
|
||||
|
||||
return super.transferTo(out);
|
||||
}
|
||||
|
||||
private static long transfer(FileChannel src, FileChannel dst) throws IOException {
|
||||
private static long transfer(FileChannel src, WritableByteChannel dst) throws IOException {
|
||||
long initialPos = src.position();
|
||||
long pos = initialPos;
|
||||
try {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue