NioUtils.java 文件源码

java
阅读 16 收藏 0 点赞 0 评论 0

项目:j2objc 作者:
/**
 * 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());
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号