Skip to content

Commit

Permalink
Testing optimized case for SourceChannelImpl
Browse files Browse the repository at this point in the history
  • Loading branch information
mkarg committed Apr 5, 2024
1 parent 6197b7b commit d5bab4e
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions test/jdk/java/nio/channels/Channels/Skip.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import java.io.InputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.channels.Channels;
import java.nio.channels.FileChannel;
import java.nio.channels.Pipe;
Expand Down Expand Up @@ -54,6 +55,9 @@ public static Object[] streams() {
// tests FileChannel.skip() optimized case
fileChannelInput(),

// tests SourceChannelImpl.skip() optimized case
sourceChannelImplInput(),

// tests InputStream.skip() default case
readableByteChannelInput()
};
Expand All @@ -80,4 +84,21 @@ private static InputStreamProvider fileChannelInput() {
};
}

/*
* Creates a provider for an input stream which wraps a pipe channel
*/
private static InputStreamProvider sourceChannelImplInput() {
return bytes -> {
Pipe pipe = Pipe.open();
new Thread(() -> {
try (OutputStream os = Channels.newOutputStream(pipe.sink())) {
os.write(bytes);
} catch (IOException e) {
throw new RuntimeException(e);
}
}).start();
return Channels.newInputStream(pipe.source());
};
}

}

0 comments on commit d5bab4e

Please sign in to comment.