Java Code Examples for java.nio.channels.spi.SelectorProvider#openPipe()
The following examples show how to use
java.nio.channels.spi.SelectorProvider#openPipe() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EmptyRead.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Exception { SelectorProvider sp = SelectorProvider.provider(); Pipe p = sp.openPipe(); Pipe.SinkChannel sink = p.sink(); Pipe.SourceChannel source = p.source(); byte[] someBytes = new byte[0]; ByteBuffer outgoingdata = ByteBuffer.wrap(someBytes); int totalWritten = 0; int written = sink.write(outgoingdata); if (written < 0) throw new Exception("Write failed"); ByteBuffer incomingdata = ByteBuffer.allocateDirect(0); int read = source.read(incomingdata); if (read < 0) throw new Exception("Read EOF"); sink.close(); source.close(); }
Example 2
Source File: EmptyRead.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Exception { SelectorProvider sp = SelectorProvider.provider(); Pipe p = sp.openPipe(); Pipe.SinkChannel sink = p.sink(); Pipe.SourceChannel source = p.source(); byte[] someBytes = new byte[0]; ByteBuffer outgoingdata = ByteBuffer.wrap(someBytes); int totalWritten = 0; int written = sink.write(outgoingdata); if (written < 0) throw new Exception("Write failed"); ByteBuffer incomingdata = ByteBuffer.allocateDirect(0); int read = source.read(incomingdata); if (read < 0) throw new Exception("Read EOF"); sink.close(); source.close(); }
Example 3
Source File: EmptyRead.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Exception { SelectorProvider sp = SelectorProvider.provider(); Pipe p = sp.openPipe(); Pipe.SinkChannel sink = p.sink(); Pipe.SourceChannel source = p.source(); byte[] someBytes = new byte[0]; ByteBuffer outgoingdata = ByteBuffer.wrap(someBytes); int totalWritten = 0; int written = sink.write(outgoingdata); if (written < 0) throw new Exception("Write failed"); ByteBuffer incomingdata = ByteBuffer.allocateDirect(0); int read = source.read(incomingdata); if (read < 0) throw new Exception("Read EOF"); sink.close(); source.close(); }
Example 4
Source File: EmptyRead.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Exception { SelectorProvider sp = SelectorProvider.provider(); Pipe p = sp.openPipe(); Pipe.SinkChannel sink = p.sink(); Pipe.SourceChannel source = p.source(); byte[] someBytes = new byte[0]; ByteBuffer outgoingdata = ByteBuffer.wrap(someBytes); int totalWritten = 0; int written = sink.write(outgoingdata); if (written < 0) throw new Exception("Write failed"); ByteBuffer incomingdata = ByteBuffer.allocateDirect(0); int read = source.read(incomingdata); if (read < 0) throw new Exception("Read EOF"); sink.close(); source.close(); }
Example 5
Source File: EmptyRead.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Exception { SelectorProvider sp = SelectorProvider.provider(); Pipe p = sp.openPipe(); Pipe.SinkChannel sink = p.sink(); Pipe.SourceChannel source = p.source(); byte[] someBytes = new byte[0]; ByteBuffer outgoingdata = ByteBuffer.wrap(someBytes); int totalWritten = 0; int written = sink.write(outgoingdata); if (written < 0) throw new Exception("Write failed"); ByteBuffer incomingdata = ByteBuffer.allocateDirect(0); int read = source.read(incomingdata); if (read < 0) throw new Exception("Read EOF"); sink.close(); source.close(); }
Example 6
Source File: PipeChannel.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Exception { for (int x=0; x<100; x++) { SelectorProvider sp = SelectorProvider.provider(); Pipe p = sp.openPipe(); Pipe.SinkChannel sink = p.sink(); Pipe.SourceChannel source = p.source(); ByteBuffer outgoingdata = ByteBuffer.allocateDirect(10); byte[] someBytes = new byte[10]; generator.nextBytes(someBytes); outgoingdata.put(someBytes); outgoingdata.flip(); int totalWritten = 0; while (totalWritten < 10) { int written = sink.write(outgoingdata); if (written < 0) throw new Exception("Write failed"); totalWritten += written; } ByteBuffer incomingdata = ByteBuffer.allocateDirect(10); int totalRead = 0; do { int bytesRead = source.read(incomingdata); if (bytesRead > 0) totalRead += bytesRead; } while(totalRead < 10); for(int i=0; i<10; i++) if (outgoingdata.get(i) != incomingdata.get(i)) throw new Exception("Pipe failed"); sink.close(); source.close(); } }
Example 7
Source File: Open.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Exception { // Load necessary classes ahead of time DatagramChannel dc = DatagramChannel.open(); Exception se = new SocketException(); SelectorProvider sp = SelectorProvider.provider(); Pipe p = sp.openPipe(); ServerSocketChannel ssc = ServerSocketChannel.open(); test1(); test2(); test3(); test4(); }
Example 8
Source File: PipeChannel.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Exception { for (int x=0; x<100; x++) { SelectorProvider sp = SelectorProvider.provider(); Pipe p = sp.openPipe(); Pipe.SinkChannel sink = p.sink(); Pipe.SourceChannel source = p.source(); ByteBuffer outgoingdata = ByteBuffer.allocateDirect(10); byte[] someBytes = new byte[10]; generator.nextBytes(someBytes); outgoingdata.put(someBytes); outgoingdata.flip(); int totalWritten = 0; while (totalWritten < 10) { int written = sink.write(outgoingdata); if (written < 0) throw new Exception("Write failed"); totalWritten += written; } ByteBuffer incomingdata = ByteBuffer.allocateDirect(10); int totalRead = 0; do { int bytesRead = source.read(incomingdata); if (bytesRead > 0) totalRead += bytesRead; } while(totalRead < 10); for(int i=0; i<10; i++) if (outgoingdata.get(i) != incomingdata.get(i)) throw new Exception("Pipe failed"); sink.close(); source.close(); } }
Example 9
Source File: Open.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Exception { // Load necessary classes ahead of time DatagramChannel dc = DatagramChannel.open(); Exception se = new SocketException(); SelectorProvider sp = SelectorProvider.provider(); Pipe p = sp.openPipe(); ServerSocketChannel ssc = ServerSocketChannel.open(); test1(); test2(); test3(); test4(); }
Example 10
Source File: PipeChannel.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Exception { for (int x=0; x<100; x++) { SelectorProvider sp = SelectorProvider.provider(); Pipe p = sp.openPipe(); Pipe.SinkChannel sink = p.sink(); Pipe.SourceChannel source = p.source(); ByteBuffer outgoingdata = ByteBuffer.allocateDirect(10); byte[] someBytes = new byte[10]; generator.nextBytes(someBytes); outgoingdata.put(someBytes); outgoingdata.flip(); int totalWritten = 0; while (totalWritten < 10) { int written = sink.write(outgoingdata); if (written < 0) throw new Exception("Write failed"); totalWritten += written; } ByteBuffer incomingdata = ByteBuffer.allocateDirect(10); int totalRead = 0; do { int bytesRead = source.read(incomingdata); if (bytesRead > 0) totalRead += bytesRead; } while(totalRead < 10); for(int i=0; i<10; i++) if (outgoingdata.get(i) != incomingdata.get(i)) throw new Exception("Pipe failed"); sink.close(); source.close(); } }
Example 11
Source File: Open.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Exception { // Load necessary classes ahead of time DatagramChannel dc = DatagramChannel.open(); Exception se = new SocketException(); SelectorProvider sp = SelectorProvider.provider(); Pipe p = sp.openPipe(); ServerSocketChannel ssc = ServerSocketChannel.open(); test1(); test2(); test3(); test4(); }
Example 12
Source File: PipeChannel.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Exception { for (int x=0; x<100; x++) { SelectorProvider sp = SelectorProvider.provider(); Pipe p = sp.openPipe(); Pipe.SinkChannel sink = p.sink(); Pipe.SourceChannel source = p.source(); ByteBuffer outgoingdata = ByteBuffer.allocateDirect(10); byte[] someBytes = new byte[10]; generator.nextBytes(someBytes); outgoingdata.put(someBytes); outgoingdata.flip(); int totalWritten = 0; while (totalWritten < 10) { int written = sink.write(outgoingdata); if (written < 0) throw new Exception("Write failed"); totalWritten += written; } ByteBuffer incomingdata = ByteBuffer.allocateDirect(10); int totalRead = 0; do { int bytesRead = source.read(incomingdata); if (bytesRead > 0) totalRead += bytesRead; } while(totalRead < 10); for(int i=0; i<10; i++) if (outgoingdata.get(i) != incomingdata.get(i)) throw new Exception("Pipe failed"); sink.close(); source.close(); } }
Example 13
Source File: Transfer.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
@Test public void testReadableByteChannel() throws Exception { int[] testSizes = { 0, 10, 1023, 1024, 1025, 2047, 2048, 2049 }; for (int size : testSizes) { SelectorProvider sp = SelectorProvider.provider(); Pipe p = sp.openPipe(); Pipe.SinkChannel sink = p.sink(); Pipe.SourceChannel source = p.source(); sink.configureBlocking(false); ByteBuffer outgoingdata = ByteBuffer.allocateDirect(size + 10); byte[] someBytes = new byte[size + 10]; generator.nextBytes(someBytes); outgoingdata.put(someBytes); outgoingdata.flip(); int totalWritten = 0; while (totalWritten < size + 10) { int written = sink.write(outgoingdata); if (written < 0) throw new Exception("Write failed"); totalWritten += written; } File f = File.createTempFile("blah"+size, null); f.deleteOnExit(); RandomAccessFile raf = new RandomAccessFile(f, "rw"); FileChannel fc = raf.getChannel(); long oldPosition = fc.position(); long bytesWritten = fc.transferFrom(source, 0, size); fc.force(true); if (bytesWritten != size) throw new RuntimeException("Transfer failed"); if (fc.position() != oldPosition) throw new RuntimeException("Position changed"); if (fc.size() != size) throw new RuntimeException("Unexpected sink size "+ fc.size()); fc.close(); sink.close(); source.close(); f.delete(); } }
Example 14
Source File: SelectPipe.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
public static void main(String[] args) throws Exception { SelectorProvider sp = SelectorProvider.provider(); Selector selector = Selector.open(); Pipe p = sp.openPipe(); Pipe.SinkChannel sink = p.sink(); Pipe.SourceChannel source = p.source(); source.configureBlocking(false); sink.configureBlocking(false); SelectionKey readkey = source.register(selector, SelectionKey.OP_READ); SelectionKey writekey = sink.register(selector, SelectionKey.OP_WRITE); ByteBuffer outgoingdata = ByteBuffer.allocateDirect(10); byte[] someBytes = new byte[10]; generator.nextBytes(someBytes); outgoingdata.put(someBytes); outgoingdata.flip(); int totalWritten = 0; while (totalWritten < 10) { int written = sink.write(outgoingdata); if (written < 0) throw new Exception("Write failed"); totalWritten += written; } if (selector.select(1000) == 0) { throw new Exception("test failed"); } ByteBuffer incomingdata = ByteBuffer.allocateDirect(10); int totalRead = 0; do { int bytesRead = source.read(incomingdata); if (bytesRead > 0) totalRead += bytesRead; } while(totalRead < 10); sink.close(); source.close(); selector.close(); for(int i=0; i<10; i++) if (outgoingdata.get(i) != incomingdata.get(i)) throw new Exception("Pipe failed"); }
Example 15
Source File: Transfer.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
private static void testReadableByteChannel(int size) throws Exception { SelectorProvider sp = SelectorProvider.provider(); Pipe p = sp.openPipe(); Pipe.SinkChannel sink = p.sink(); Pipe.SourceChannel source = p.source(); sink.configureBlocking(false); ByteBuffer outgoingdata = ByteBuffer.allocateDirect(size + 10); byte[] someBytes = new byte[size + 10]; generator.nextBytes(someBytes); outgoingdata.put(someBytes); outgoingdata.flip(); int totalWritten = 0; while (totalWritten < size + 10) { int written = sink.write(outgoingdata); if (written < 0) throw new Exception("Write failed"); totalWritten += written; } File f = File.createTempFile("blah"+size, null); f.deleteOnExit(); RandomAccessFile raf = new RandomAccessFile(f, "rw"); FileChannel fc = raf.getChannel(); long oldPosition = fc.position(); long bytesWritten = fc.transferFrom(source, 0, size); fc.force(true); if (bytesWritten != size) throw new RuntimeException("Transfer failed"); if (fc.position() != oldPosition) throw new RuntimeException("Position changed"); if (fc.size() != size) throw new RuntimeException("Unexpected sink size "+ fc.size()); fc.close(); sink.close(); source.close(); f.delete(); }
Example 16
Source File: SelectPipe.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
public static void main(String[] args) throws Exception { SelectorProvider sp = SelectorProvider.provider(); Selector selector = Selector.open(); Pipe p = sp.openPipe(); Pipe.SinkChannel sink = p.sink(); Pipe.SourceChannel source = p.source(); source.configureBlocking(false); sink.configureBlocking(false); SelectionKey readkey = source.register(selector, SelectionKey.OP_READ); SelectionKey writekey = sink.register(selector, SelectionKey.OP_WRITE); ByteBuffer outgoingdata = ByteBuffer.allocateDirect(10); byte[] someBytes = new byte[10]; generator.nextBytes(someBytes); outgoingdata.put(someBytes); outgoingdata.flip(); int totalWritten = 0; while (totalWritten < 10) { int written = sink.write(outgoingdata); if (written < 0) throw new Exception("Write failed"); totalWritten += written; } if (selector.select(1000) == 0) { throw new Exception("test failed"); } ByteBuffer incomingdata = ByteBuffer.allocateDirect(10); int totalRead = 0; do { int bytesRead = source.read(incomingdata); if (bytesRead > 0) totalRead += bytesRead; } while(totalRead < 10); sink.close(); source.close(); selector.close(); for(int i=0; i<10; i++) if (outgoingdata.get(i) != incomingdata.get(i)) throw new Exception("Pipe failed"); }
Example 17
Source File: Transfer.java From jdk8u_jdk with GNU General Public License v2.0 | 4 votes |
private static void testReadableByteChannel(int size) throws Exception { SelectorProvider sp = SelectorProvider.provider(); Pipe p = sp.openPipe(); Pipe.SinkChannel sink = p.sink(); Pipe.SourceChannel source = p.source(); sink.configureBlocking(false); ByteBuffer outgoingdata = ByteBuffer.allocateDirect(size + 10); byte[] someBytes = new byte[size + 10]; generator.nextBytes(someBytes); outgoingdata.put(someBytes); outgoingdata.flip(); int totalWritten = 0; while (totalWritten < size + 10) { int written = sink.write(outgoingdata); if (written < 0) throw new Exception("Write failed"); totalWritten += written; } File f = File.createTempFile("blah"+size, null); f.deleteOnExit(); RandomAccessFile raf = new RandomAccessFile(f, "rw"); FileChannel fc = raf.getChannel(); long oldPosition = fc.position(); long bytesWritten = fc.transferFrom(source, 0, size); fc.force(true); if (bytesWritten != size) throw new RuntimeException("Transfer failed"); if (fc.position() != oldPosition) throw new RuntimeException("Position changed"); if (fc.size() != size) throw new RuntimeException("Unexpected sink size "+ fc.size()); fc.close(); sink.close(); source.close(); f.delete(); }
Example 18
Source File: Transfer.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
private static void testReadableByteChannel(int size) throws Exception { SelectorProvider sp = SelectorProvider.provider(); Pipe p = sp.openPipe(); Pipe.SinkChannel sink = p.sink(); Pipe.SourceChannel source = p.source(); sink.configureBlocking(false); ByteBuffer outgoingdata = ByteBuffer.allocateDirect(size + 10); byte[] someBytes = new byte[size + 10]; generator.nextBytes(someBytes); outgoingdata.put(someBytes); outgoingdata.flip(); int totalWritten = 0; while (totalWritten < size + 10) { int written = sink.write(outgoingdata); if (written < 0) throw new Exception("Write failed"); totalWritten += written; } File f = File.createTempFile("blah"+size, null); f.deleteOnExit(); RandomAccessFile raf = new RandomAccessFile(f, "rw"); FileChannel fc = raf.getChannel(); long oldPosition = fc.position(); long bytesWritten = fc.transferFrom(source, 0, size); fc.force(true); if (bytesWritten != size) throw new RuntimeException("Transfer failed"); if (fc.position() != oldPosition) throw new RuntimeException("Position changed"); if (fc.size() != size) throw new RuntimeException("Unexpected sink size "+ fc.size()); fc.close(); sink.close(); source.close(); f.delete(); }
Example 19
Source File: SelectPipe.java From jdk8u_jdk with GNU General Public License v2.0 | 4 votes |
public static void main(String[] args) throws Exception { SelectorProvider sp = SelectorProvider.provider(); Selector selector = Selector.open(); Pipe p = sp.openPipe(); Pipe.SinkChannel sink = p.sink(); Pipe.SourceChannel source = p.source(); source.configureBlocking(false); sink.configureBlocking(false); SelectionKey readkey = source.register(selector, SelectionKey.OP_READ); SelectionKey writekey = sink.register(selector, SelectionKey.OP_WRITE); ByteBuffer outgoingdata = ByteBuffer.allocateDirect(10); byte[] someBytes = new byte[10]; generator.nextBytes(someBytes); outgoingdata.put(someBytes); outgoingdata.flip(); int totalWritten = 0; while (totalWritten < 10) { int written = sink.write(outgoingdata); if (written < 0) throw new Exception("Write failed"); totalWritten += written; } if (selector.select(1000) == 0) { throw new Exception("test failed"); } ByteBuffer incomingdata = ByteBuffer.allocateDirect(10); int totalRead = 0; do { int bytesRead = source.read(incomingdata); if (bytesRead > 0) totalRead += bytesRead; } while(totalRead < 10); sink.close(); source.close(); selector.close(); for(int i=0; i<10; i++) if (outgoingdata.get(i) != incomingdata.get(i)) throw new Exception("Pipe failed"); }
Example 20
Source File: Transfer.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
private static void testReadableByteChannel(int size) throws Exception { SelectorProvider sp = SelectorProvider.provider(); Pipe p = sp.openPipe(); Pipe.SinkChannel sink = p.sink(); Pipe.SourceChannel source = p.source(); sink.configureBlocking(false); ByteBuffer outgoingdata = ByteBuffer.allocateDirect(size + 10); byte[] someBytes = new byte[size + 10]; generator.nextBytes(someBytes); outgoingdata.put(someBytes); outgoingdata.flip(); int totalWritten = 0; while (totalWritten < size + 10) { int written = sink.write(outgoingdata); if (written < 0) throw new Exception("Write failed"); totalWritten += written; } File f = File.createTempFile("blah"+size, null); f.deleteOnExit(); RandomAccessFile raf = new RandomAccessFile(f, "rw"); FileChannel fc = raf.getChannel(); long oldPosition = fc.position(); long bytesWritten = fc.transferFrom(source, 0, size); fc.force(true); if (bytesWritten != size) throw new RuntimeException("Transfer failed"); if (fc.position() != oldPosition) throw new RuntimeException("Position changed"); if (fc.size() != size) throw new RuntimeException("Unexpected sink size "+ fc.size()); fc.close(); sink.close(); source.close(); f.delete(); }