use of java.nio.channels.IllegalSelectorException in project jetty.project by eclipse.
the class Response method setContentType.
@Override
public void setContentType(String contentType) {
if (isCommitted() || isIncluding())
return;
if (contentType == null) {
if (isWriting() && _characterEncoding != null)
throw new IllegalSelectorException();
if (_locale == null)
_characterEncoding = null;
_mimeType = null;
_contentType = null;
_fields.remove(HttpHeader.CONTENT_TYPE);
} else {
_contentType = contentType;
_mimeType = MimeTypes.CACHE.get(contentType);
String charset;
if (_mimeType != null && _mimeType.getCharset() != null && !_mimeType.isCharsetAssumed())
charset = _mimeType.getCharsetString();
else
charset = MimeTypes.getCharsetFromContentType(contentType);
if (charset == null) {
switch(_encodingFrom) {
case NOT_SET:
break;
case INFERRED:
case SET_CONTENT_TYPE:
if (isWriting()) {
_mimeType = null;
_contentType = _contentType + ";charset=" + _characterEncoding;
} else {
_encodingFrom = EncodingFrom.NOT_SET;
_characterEncoding = null;
}
break;
case SET_LOCALE:
case SET_CHARACTER_ENCODING:
{
_contentType = contentType + ";charset=" + _characterEncoding;
_mimeType = null;
}
}
} else if (isWriting() && !charset.equalsIgnoreCase(_characterEncoding)) {
// too late to change the character encoding;
_mimeType = null;
_contentType = MimeTypes.getContentTypeWithoutCharset(_contentType);
if (_characterEncoding != null)
_contentType = _contentType + ";charset=" + _characterEncoding;
} else {
_characterEncoding = charset;
_encodingFrom = EncodingFrom.SET_CONTENT_TYPE;
}
if (HttpGenerator.__STRICT || _mimeType == null)
_fields.put(HttpHeader.CONTENT_TYPE, _contentType);
else {
_contentType = _mimeType.asString();
_fields.put(_mimeType.getContentTypeField());
}
}
}
use of java.nio.channels.IllegalSelectorException in project robovm by robovm.
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.IllegalSelectorException 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.IllegalSelectorException 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
}
}
use of java.nio.channels.IllegalSelectorException in project robovm by robovm.
the class IllegalSelectorExceptionTest method test_Constructor.
/**
* @tests {@link java.nio.channels.IllegalSelectorException#IllegalSelectorException()}
*/
public void test_Constructor() {
IllegalSelectorException e = new IllegalSelectorException();
assertNull(e.getMessage());
assertNull(e.getLocalizedMessage());
assertNull(e.getCause());
}
Aggregations