當前位置: 首頁>>代碼示例>>Java>>正文


Java SelectorProvider.provider方法代碼示例

本文整理匯總了Java中java.nio.channels.spi.SelectorProvider.provider方法的典型用法代碼示例。如果您正苦於以下問題:Java SelectorProvider.provider方法的具體用法?Java SelectorProvider.provider怎麽用?Java SelectorProvider.provider使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.nio.channels.spi.SelectorProvider的用法示例。


在下文中一共展示了SelectorProvider.provider方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: main

import java.nio.channels.spi.SelectorProvider; //導入方法依賴的package包/類
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();
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:23,代碼來源:EmptyRead.java

示例2: main

import java.nio.channels.spi.SelectorProvider; //導入方法依賴的package包/類
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();
    }
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:15,代碼來源:Open.java

示例3: test3

import java.nio.channels.spi.SelectorProvider; //導入方法依賴的package包/類
static void test3() {
    SelectorProvider sp = SelectorProvider.provider();
    for (int i=0; i<11000; i++) {
        try {
            Pipe p = sp.openPipe();
        } catch (Exception e) {
            // Presumably "Too many open files"
        }
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:11,代碼來源:Open.java

示例4: main

import java.nio.channels.spi.SelectorProvider; //導入方法依賴的package包/類
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();
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:37,代碼來源:PipeChannel.java

示例5: provider

import java.nio.channels.spi.SelectorProvider; //導入方法依賴的package包/類
private static SelectorProvider provider() {
    SelectorProvider p = SelectorProvider.provider();
    if (!(p instanceof SelectorProviderImpl))
        throw new UnsupportedOperationException();
    return p;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:7,代碼來源:Secrets.java

示例6: testReadableByteChannel

import java.nio.channels.spi.SelectorProvider; //導入方法依賴的package包/類
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();
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:45,代碼來源:Transfer.java

示例7: main

import java.nio.channels.spi.SelectorProvider; //導入方法依賴的package包/類
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");
    }
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:49,代碼來源:SelectPipe.java

示例8: testReadableByteChannel

import java.nio.channels.spi.SelectorProvider; //導入方法依賴的package包/類
@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();
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:50,代碼來源:Transfer.java


注:本文中的java.nio.channels.spi.SelectorProvider.provider方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。