/**
* Gets the supplied option from the channel if option is a member of allowedOptions.
*
* @throws IOException
* if the value could not be read due to IO errors.
* @throws IllegalArgumentException
* if the socket option is invalid.
* @throws UnsupportedOperationException
* if the option is not a member of allowedOptions.
* @throws ClosedChannelException
* if the channel is closed
*/
public static <T> T getSocketOption(
FileDescriptorChannel channel, Set<SocketOption<?>> allowedOptions,
SocketOption<T> option)
throws IOException {
if (!(option instanceof StandardSocketOptions.SocketOptionImpl)) {
throw new IllegalArgumentException("SocketOption must come from StandardSocketOptions");
}
if (!allowedOptions.contains(option)) {
throw new UnsupportedOperationException(
option + " is not supported for this type of socket");
}
if (!channel.getFD().valid()) {
throw new ClosedChannelException();
}
return ((StandardSocketOptions.SocketOptionImpl<T>) option).getValue(channel.getFD());
}
NioUtils.java 文件源码
java
阅读 16
收藏 0
点赞 0
评论 0
项目:j2objc
作者:
评论列表
文章目录