use of java.nio.channels.IllegalBlockingModeException in project j2objc by google.
the class SocketChannelTest method test_socket_getOutputStream_nonBlocking_read_Exception.
public void test_socket_getOutputStream_nonBlocking_read_Exception() throws IOException {
byte[] buf = new byte[1];
channel1.connect(this.localAddr1);
InputStream is = channel1.socket().getInputStream();
channel1.configureBlocking(false);
try {
is.read();
fail();
} catch (IllegalBlockingModeException expected) {
}
try {
is.read(null);
fail();
} catch (NullPointerException expected) {
// Any of these exceptions are possible.
} catch (IllegalBlockingModeException expected) {
// Any of these exceptions are possible.
}
try {
is.read(buf, -1, 1);
fail();
} catch (IndexOutOfBoundsException expected) {
// Any of these exceptions are possible.
} catch (IllegalBlockingModeException expected) {
// Any of these exceptions are possible.
}
try {
is.read(buf, 0, -1);
fail();
} catch (IndexOutOfBoundsException expected) {
// Any of these exceptions are possible.
} catch (IllegalBlockingModeException expected) {
// Any of these exceptions are possible.
}
try {
is.read(buf, 0, 2);
fail();
} catch (IndexOutOfBoundsException expected) {
// Any of these exceptions are possible.
} catch (IllegalBlockingModeException expected) {
// Any of these exceptions are possible.
}
try {
is.read(buf, 2, 0);
fail();
} catch (IndexOutOfBoundsException expected) {
// Any of these exceptions are possible.
} catch (IllegalBlockingModeException expected) {
// Any of these exceptions are possible.
}
try {
is.read(null, 0, 0);
fail();
} catch (NullPointerException expected) {
// Any of these exceptions are possible.
} catch (IllegalBlockingModeException expected) {
// Any of these exceptions are possible.
}
is.close();
try {
is.read();
fail();
} catch (IllegalBlockingModeException expected) {
// Any of these exceptions are possible.
} catch (IOException expected) {
// Any of these exceptions are possible.
}
try {
is.read(null);
fail();
} catch (NullPointerException expected) {
// Any of these exceptions are possible.
} catch (IllegalBlockingModeException expected) {
// Any of these exceptions are possible.
} catch (IOException expected) {
// Any of these exceptions are possible.
}
try {
is.read(buf, -1, 1);
fail();
} catch (IndexOutOfBoundsException expected) {
// Any of these exceptions are possible.
} catch (IllegalBlockingModeException expected) {
// Any of these exceptions are possible.
} catch (IOException expected) {
// Any of these exceptions are possible.
}
try {
is.read(buf, 0, -1);
fail();
} catch (IndexOutOfBoundsException expected) {
// Any of these exceptions are possible.
} catch (IllegalBlockingModeException expected) {
// Any of these exceptions are possible.
} catch (IOException expected) {
// Any of these exceptions are possible.
}
try {
is.read(buf, 0, 2);
fail();
} catch (IndexOutOfBoundsException expected) {
// Any of these exceptions are possible.
} catch (IllegalBlockingModeException expected) {
// Any of these exceptions are possible.
} catch (IOException expected) {
// Any of these exceptions are possible.
}
try {
is.read(buf, 2, 0);
fail();
} catch (IndexOutOfBoundsException expected) {
// Any of these exceptions are possible.
} catch (IllegalBlockingModeException expected) {
// Any of these exceptions are possible.
} catch (IOException expected) {
// Any of these exceptions are possible.
}
try {
is.read(null, 0, 0);
fail();
} catch (NullPointerException expected) {
// Any of these exceptions are possible.
} catch (IllegalBlockingModeException expected) {
// Any of these exceptions are possible.
} catch (IOException expected) {
// Any of these exceptions are possible.
}
}
use of java.nio.channels.IllegalBlockingModeException in project j2objc by google.
the class AbstractSelectableChannel method register.
/**
* Registers this channel with the specified selector for the specified
* interest set. If the channel is already registered with the selector, the
* {@link SelectionKey interest set} is updated to {@code interestSet} and
* the corresponding selection key is returned. If the channel is not yet
* registered, this method calls the {@code register} method of
* {@code selector} and adds the selection key to this channel's key set.
*
* @param selector
* the selector with which to register this channel.
* @param interestSet
* this channel's {@link SelectionKey interest set}.
* @param attachment
* the object to attach, can be {@code null}.
* @return the selection key for this registration.
* @throws CancelledKeyException
* if this channel is registered but its key has been canceled.
* @throws ClosedChannelException
* if this channel is closed.
* @throws IllegalArgumentException
* if {@code interestSet} is not supported by this channel.
* @throws IllegalBlockingModeException
* if this channel is in blocking mode.
* @throws IllegalSelectorException
* if this channel does not have the same provider as the given
* selector.
*/
@Override
public final SelectionKey register(Selector selector, int interestSet, Object attachment) throws ClosedChannelException {
if (!isOpen()) {
throw new ClosedChannelException();
}
if (!((interestSet & ~validOps()) == 0)) {
throw new IllegalArgumentException("no valid ops in interest set: " + interestSet);
}
synchronized (blockingLock) {
if (isBlocking) {
throw new IllegalBlockingModeException();
}
if (!selector.isOpen()) {
if (interestSet == 0) {
// throw ISE exactly to keep consistency
throw new IllegalSelectorException();
}
// throw NPE exactly to keep consistency
throw new NullPointerException("selector not open");
}
SelectionKey key = keyFor(selector);
if (key == null) {
key = ((AbstractSelector) selector).register(this, interestSet, attachment);
keyList.add(key);
} else {
if (!key.isValid()) {
throw new CancelledKeyException();
}
key.interestOps(interestSet);
key.attach(attachment);
}
return key;
}
}
use of java.nio.channels.IllegalBlockingModeException in project robovm by robovm.
the class ScannerTest method test_Constructor_LReadableByteChannel.
public void test_Constructor_LReadableByteChannel() throws IOException {
ServerSocketChannel ssc = ServerSocketChannel.open();
ssc.socket().bind(null);
SocketChannel sc = SocketChannel.open();
sc.connect(ssc.socket().getLocalSocketAddress());
sc.configureBlocking(false);
assertFalse(sc.isBlocking());
ssc.accept().close();
ssc.close();
assertFalse(sc.isBlocking());
Scanner s = new Scanner(sc);
try {
s.hasNextInt();
fail();
} catch (IllegalBlockingModeException expected) {
}
sc.close();
}
use of java.nio.channels.IllegalBlockingModeException in project robovm by robovm.
the class AbstractSelectableChannelTest method test_configureBlocking_Z_IllegalBlockingMode.
/**
* @tests AbstractSelectableChannel#configureBlocking(boolean)
*/
public void test_configureBlocking_Z_IllegalBlockingMode() throws Exception {
SocketChannel sc = SocketChannel.open();
sc.configureBlocking(false);
Selector acceptSelector = SelectorProvider.provider().openSelector();
SelectionKey acceptKey = sc.register(acceptSelector, SelectionKey.OP_READ, null);
assertEquals(sc.keyFor(acceptSelector), acceptKey);
SelectableChannel getChannel = sc.configureBlocking(false);
assertEquals(getChannel, sc);
try {
sc.configureBlocking(true);
fail("Should throw IllegalBlockingModeException");
} catch (IllegalBlockingModeException e) {
// expected
}
}
use of java.nio.channels.IllegalBlockingModeException in project robovm by robovm.
the class AbstractSelectableChannelTest method test_register_LSelectorILObject_IllegalArgument.
/**
* @tests AbstractSelectableChannel#register(Selector, int, Object)
*/
public void test_register_LSelectorILObject_IllegalArgument() throws IOException {
Selector acceptSelector = SelectorProvider.provider().openSelector();
assertTrue(acceptSelector.isOpen());
MockSelectableChannel msc = new MockSelectableChannel(SelectorProvider.provider());
msc.configureBlocking(false);
// in nonblocking mode
try {
//different SelectionKey with validOps
msc.register(acceptSelector, SelectionKey.OP_READ, null);
fail("Should throw IllegalArgumentException");
} catch (IllegalArgumentException e) {
// expected
}
try {
msc.register(null, 0, null);
fail("Should throw NullPointerException");
} catch (NullPointerException e) {
// expected
}
// in nonblocking mode, if selector closed
acceptSelector.close();
try {
msc.register(acceptSelector, SelectionKey.OP_READ, null);
fail("Should throw IllegalArgumentException");
} catch (IllegalArgumentException e) {
// expected
}
try {
msc.register(null, 0, null);
fail("Should throw NullPointerException");
} catch (NullPointerException e) {
// expected
}
try {
msc.register(acceptSelector, 0, null);
fail("Should throw IllegalSelectorException");
} catch (IllegalSelectorException e) {
// expected
}
acceptSelector = SelectorProvider.provider().openSelector();
// test in blocking mode
msc.configureBlocking(true);
try {
msc.register(acceptSelector, SelectionKey.OP_READ, null);
fail("Should throw IllegalArgumentException");
} catch (IllegalArgumentException e) {
// expected
}
try {
msc.register(null, 0, null);
fail("Should throw IllegalBlockingModeException");
} catch (IllegalBlockingModeException e) {
// expected
}
acceptSelector.close();
// in blocking mode, if selector closed
try {
msc.register(acceptSelector, SelectionKey.OP_READ, null);
fail("Should throw IllegalArgumentException");
} catch (IllegalArgumentException e) {
// expected
}
try {
msc.register(null, 0, null);
fail("Should throw IllegalBlockingModeException");
} catch (IllegalBlockingModeException e) {
// expected
}
// register with an object
Object argObj = new Object();
SocketChannel sc = SocketChannel.open();
sc.configureBlocking(false);
try {
sc.register(null, SelectionKey.OP_READ, argObj);
fail("Should throw NullPointerException");
} catch (NullPointerException e) {
// expected
}
// if channel closed
msc.close();
try {
msc.register(acceptSelector, SelectionKey.OP_READ, null);
fail("Should throw ClosedChannelException");
} catch (ClosedChannelException e) {
// expected
}
}
Aggregations