524N/A/*
2362N/A * Copyright (c) 2007, 2009, Oracle and/or its affiliates. All rights reserved.
524N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
524N/A *
524N/A * This code is free software; you can redistribute it and/or modify it
524N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
524N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
524N/A *
524N/A * This code is distributed in the hope that it will be useful, but WITHOUT
524N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
524N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
524N/A * version 2 for more details (a copy is included in the LICENSE file that
524N/A * accompanied this code).
524N/A *
524N/A * You should have received a copy of the GNU General Public License version
524N/A * 2 along with this work; if not, write to the Free Software Foundation,
524N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
524N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
524N/A */
524N/A
524N/Apackage java.nio.channels;
524N/A
524N/Aimport java.net.SocketOption;
524N/Aimport java.net.SocketAddress;
524N/Aimport java.util.Set;
524N/Aimport java.io.IOException;
524N/A
524N/A/**
524N/A * A channel to a network socket.
524N/A *
524N/A * <p> A channel that implements this interface is a channel to a network
524N/A * socket. The {@link #bind(SocketAddress) bind} method is used to bind the
524N/A * socket to a local {@link SocketAddress address}, the {@link #getLocalAddress()
524N/A * getLocalAddress} method returns the address that the socket is bound to, and
524N/A * the {@link #setOption(SocketOption,Object) setOption} and {@link
524N/A * #getOption(SocketOption) getOption} methods are used to set and query socket
524N/A * options. An implementation of this interface should specify the socket options
524N/A * that it supports.
524N/A *
524N/A * <p> The {@link #bind bind} and {@link #setOption setOption} methods that do
524N/A * not otherwise have a value to return are specified to return the network
524N/A * channel upon which they are invoked. This allows method invocations to be
524N/A * chained. Implementations of this interface should specialize the return type
524N/A * so that method invocations on the implementation class can be chained.
524N/A *
524N/A * @since 1.7
524N/A */
524N/A
524N/Apublic interface NetworkChannel
524N/A extends Channel
524N/A{
524N/A /**
524N/A * Binds the channel's socket to a local address.
524N/A *
524N/A * <p> This method is used to establish an association between the socket and
524N/A * a local address. Once an association is established then the socket remains
524N/A * bound until the channel is closed. If the {@code local} parameter has the
524N/A * value {@code null} then the socket will be bound to an address that is
524N/A * assigned automatically.
524N/A *
524N/A * @param local
524N/A * The address to bind the socket, or {@code null} to bind the socket
524N/A * to an automatically assigned socket address
524N/A *
524N/A * @return This channel
524N/A *
524N/A * @throws AlreadyBoundException
524N/A * If the socket is already bound
524N/A * @throws UnsupportedAddressTypeException
524N/A * If the type of the given address is not supported
524N/A * @throws ClosedChannelException
524N/A * If the channel is closed
524N/A * @throws IOException
524N/A * If some other I/O error occurs
524N/A * @throws SecurityException
524N/A * If a security manager is installed and it denies an unspecified
524N/A * permission. An implementation of this interface should specify
524N/A * any required permissions.
524N/A *
524N/A * @see #getLocalAddress
524N/A */
524N/A NetworkChannel bind(SocketAddress local) throws IOException;
524N/A
524N/A /**
524N/A * Returns the socket address that this channel's socket is bound to, or
524N/A * {@code null} if the socket is not bound.
524N/A *
524N/A * <p> Where the channel is {@link #bind bound} to an Internet Protocol
524N/A * socket address then the return value from this method is of type {@link
524N/A * java.net.InetSocketAddress}.
524N/A *
524N/A * @return The socket address that the socket is bound to, or {@code null}
893N/A * if the channel's socket is not bound
524N/A *
893N/A * @throws ClosedChannelException
893N/A * If the channel is closed
524N/A * @throws IOException
524N/A * If an I/O error occurs
524N/A */
524N/A SocketAddress getLocalAddress() throws IOException;
524N/A
524N/A /**
524N/A * Sets the value of a socket option.
524N/A *
524N/A * @param name
524N/A * The socket option
524N/A * @param value
524N/A * The value of the socket option. A value of {@code null} may be
524N/A * a valid value for some socket options.
524N/A *
524N/A * @return This channel
524N/A *
893N/A * @throws UnsupportedOperationException
893N/A * If the socket option is not supported by this channel
524N/A * @throws IllegalArgumentException
893N/A * If the value is not a valid value for this socket option
524N/A * @throws ClosedChannelException
524N/A * If this channel is closed
524N/A * @throws IOException
524N/A * If an I/O error occurs
524N/A *
4216N/A * @see java.net.StandardSocketOptions
524N/A */
524N/A <T> NetworkChannel setOption(SocketOption<T> name, T value) throws IOException;
524N/A
524N/A /**
524N/A * Returns the value of a socket option.
524N/A *
524N/A * @param name
524N/A * The socket option
524N/A *
524N/A * @return The value of the socket option. A value of {@code null} may be
524N/A * a valid value for some socket options.
524N/A *
893N/A * @throws UnsupportedOperationException
524N/A * If the socket option is not supported by this channel
524N/A * @throws ClosedChannelException
524N/A * If this channel is closed
524N/A * @throws IOException
524N/A * If an I/O error occurs
524N/A *
4216N/A * @see java.net.StandardSocketOptions
524N/A */
524N/A <T> T getOption(SocketOption<T> name) throws IOException;
524N/A
524N/A /**
524N/A * Returns a set of the socket options supported by this channel.
524N/A *
524N/A * <p> This method will continue to return the set of options even after the
524N/A * channel has been closed.
524N/A *
524N/A * @return A set of the socket options supported by this channel
524N/A */
893N/A Set<SocketOption<?>> supportedOptions();
524N/A}