Search in sources :

Example 36 with IllegalBlockingModeException

use of java.nio.channels.IllegalBlockingModeException in project j2objc by google.

the class SocketChannelTest method test_socket_getOutputStream_nonBlocking_write_Exception.

public void test_socket_getOutputStream_nonBlocking_write_Exception() throws IOException {
    byte[] buf = new byte[1];
    channel1.connect(this.localAddr1);
    OutputStream os = channel1.socket().getOutputStream();
    channel1.configureBlocking(false);
    try {
        os.write(1);
        fail();
    } catch (IllegalBlockingModeException expected) {
    }
    try {
        os.write(null);
        fail();
    } catch (IllegalBlockingModeException expected) {
    // Any of these exceptions are possible.
    } catch (NullPointerException expected) {
    // Any of these exceptions are possible.
    }
    try {
        os.write(buf, -1, 1);
        fail();
    } catch (IllegalBlockingModeException expected) {
    // Any of these exceptions are possible.
    } catch (IndexOutOfBoundsException expected) {
    // Any of these exceptions are possible.
    }
    try {
        os.write(buf, 0, -1);
        fail();
    } catch (IllegalBlockingModeException expected) {
    // Any of these exceptions are possible.
    } catch (IndexOutOfBoundsException expected) {
    // Any of these exceptions are possible.
    }
    try {
        os.write(buf, 0, 2);
        fail();
    } catch (IllegalBlockingModeException expected) {
    // Any of these exceptions are possible.
    } catch (IndexOutOfBoundsException expected) {
    // Any of these exceptions are possible.
    }
    try {
        os.write(buf, 2, 1);
        fail();
    } catch (IllegalBlockingModeException expected) {
    // Any of these exceptions are possible.
    } catch (IndexOutOfBoundsException expected) {
    // Any of these exceptions are possible.
    }
    try {
        os.write(null, 0, 1);
        fail();
    } catch (IllegalBlockingModeException expected) {
    // Any of these exceptions are possible.
    } catch (NullPointerException expected) {
    // Any of these exceptions are possible.
    }
    os.close();
    try {
        os.write(1);
        fail();
    } catch (IllegalBlockingModeException expected) {
    }
    try {
        os.write(null);
        fail();
    } catch (IllegalBlockingModeException expected) {
    // Any of these exceptions are possible.
    } catch (NullPointerException expected) {
    // Any of these exceptions are possible.
    }
    try {
        os.write(buf, -1, 1);
        fail();
    } catch (IllegalBlockingModeException expected) {
    // Any of these exceptions are possible.
    } catch (IndexOutOfBoundsException expected) {
    // Any of these exceptions are possible.
    }
    try {
        os.write(buf, 0, -1);
        fail();
    } catch (IllegalBlockingModeException expected) {
    // Any of these exceptions are possible.
    } catch (IndexOutOfBoundsException expected) {
    // Any of these exceptions are possible.
    }
    try {
        os.write(buf, 0, 2);
        fail();
    } catch (IllegalBlockingModeException expected) {
    // Any of these exceptions are possible.
    } catch (IndexOutOfBoundsException expected) {
    // Any of these exceptions are possible.
    }
    try {
        os.write(buf, 2, 0);
        fail();
    } catch (IllegalBlockingModeException expected) {
    // Any of these exceptions are possible.
    } catch (IndexOutOfBoundsException expected) {
    // Any of these exceptions are possible.
    }
    try {
        os.write(null, 0, 0);
        fail();
    } catch (IllegalBlockingModeException expected) {
    // Any of these exceptions are possible.
    } catch (NullPointerException expected) {
    // Any of these exceptions are possible.
    }
}
Also used : OutputStream(java.io.OutputStream) IllegalBlockingModeException(java.nio.channels.IllegalBlockingModeException)

Aggregations

IllegalBlockingModeException (java.nio.channels.IllegalBlockingModeException)36 ServerSocket (java.net.ServerSocket)14 SocketChannel (java.nio.channels.SocketChannel)10 IOException (java.io.IOException)7 OutputStream (java.io.OutputStream)7 Socket (java.net.Socket)7 ClosedChannelException (java.nio.channels.ClosedChannelException)7 SelectionKey (java.nio.channels.SelectionKey)7 Selector (java.nio.channels.Selector)6 ServerSocketChannel (java.nio.channels.ServerSocketChannel)6 BindException (java.net.BindException)5 InetSocketAddress (java.net.InetSocketAddress)5 SocketTimeoutException (java.net.SocketTimeoutException)5 IllegalSelectorException (java.nio.channels.IllegalSelectorException)5 InputStream (java.io.InputStream)4 DatagramSocket (java.net.DatagramSocket)4 SocketException (java.net.SocketException)4 UnknownHostException (java.net.UnknownHostException)4 DatagramChannel (java.nio.channels.DatagramChannel)4 SocketAddress (java.net.SocketAddress)3