< prev index next >

src/java.base/share/classes/java/nio/channels/DatagramChannel.java

Print this page

133 
134     /**
135      * Opens a datagram channel.
136      *
137      * <p> The new channel is created by invoking the {@link
138      * java.nio.channels.spi.SelectorProvider#openDatagramChannel()
139      * openDatagramChannel} method of the system-wide default {@link
140      * java.nio.channels.spi.SelectorProvider} object.  The channel will not be
141      * connected.
142      *
143      * <p> The {@link ProtocolFamily ProtocolFamily} of the channel's socket
144      * is platform (and possibly configuration) dependent and therefore unspecified.
145      * The {@link #open(ProtocolFamily) open} allows the protocol family to be
146      * selected when opening a datagram channel, and should be used to open
147      * datagram channels that are intended for Internet Protocol multicasting.
148      *
149      * @return  A new datagram channel
150      *
151      * @throws  IOException
152      *          If an I/O error occurs



153      */
154     public static DatagramChannel open() throws IOException {
155         return SelectorProvider.provider().openDatagramChannel();
156     }
157 
158     /**
159      * Opens a datagram channel.
160      *
161      * <p> The {@code family} parameter is used to specify the {@link
162      * ProtocolFamily}. If the datagram channel is to be used for IP multicasting
163      * then this should correspond to the address type of the multicast groups
164      * that this channel will join.
165      *
166      * <p> The new channel is created by invoking the {@link
167      * java.nio.channels.spi.SelectorProvider#openDatagramChannel(ProtocolFamily)
168      * openDatagramChannel} method of the system-wide default {@link
169      * java.nio.channels.spi.SelectorProvider} object.  The channel will not be
170      * connected.
171      *



172      * @param   family
173      *          The protocol family
174      *
175      * @return  A new datagram channel
176      *
177      * @throws  UnsupportedOperationException
178      *          If the specified protocol family is not supported. For example,
179      *          suppose the parameter is specified as {@link
180      *          java.net.StandardProtocolFamily#INET6 StandardProtocolFamily.INET6}
181      *          but IPv6 is not enabled on the platform.
182      * @throws  IOException
183      *          If an I/O error occurs
184      *



185      * @since   1.7
186      */
187     public static DatagramChannel open(ProtocolFamily family) throws IOException {
188         return SelectorProvider.provider().openDatagramChannel(requireNonNull(family));
189     }
190 
191     /**
192      * Returns an operation set identifying this channel's supported
193      * operations.
194      *
195      * <p> Datagram channels support reading and writing, so this method
196      * returns {@code (}{@link SelectionKey#OP_READ} {@code |}&nbsp;{@link
197      * SelectionKey#OP_WRITE}{@code )}.
198      *
199      * @return  The valid-operation set
200      */
201     public final int validOps() {
202         return (SelectionKey.OP_READ
203                 | SelectionKey.OP_WRITE);
204     }

612     /**
613      * {@inheritDoc}
614      * <p>
615      * If there is a security manager set, its {@code checkConnect} method is
616      * called with the local address and {@code -1} as its arguments to see
617      * if the operation is allowed. If the operation is not allowed,
618      * a {@code SocketAddress} representing the
619      * {@link java.net.InetAddress#getLoopbackAddress loopback} address and the
620      * local port of the channel's socket is returned.
621      *
622      * @return  The {@code SocketAddress} that the socket is bound to, or the
623      *          {@code SocketAddress} representing the loopback address if
624      *          denied by the security manager, or {@code null} if the
625      *          channel's socket is not bound
626      *
627      * @throws  ClosedChannelException     {@inheritDoc}
628      * @throws  IOException                {@inheritDoc}
629      */
630     @Override
631     public abstract SocketAddress getLocalAddress() throws IOException;
632 
633 }

133 
134     /**
135      * Opens a datagram channel.
136      *
137      * <p> The new channel is created by invoking the {@link
138      * java.nio.channels.spi.SelectorProvider#openDatagramChannel()
139      * openDatagramChannel} method of the system-wide default {@link
140      * java.nio.channels.spi.SelectorProvider} object.  The channel will not be
141      * connected.
142      *
143      * <p> The {@link ProtocolFamily ProtocolFamily} of the channel's socket
144      * is platform (and possibly configuration) dependent and therefore unspecified.
145      * The {@link #open(ProtocolFamily) open} allows the protocol family to be
146      * selected when opening a datagram channel, and should be used to open
147      * datagram channels that are intended for Internet Protocol multicasting.
148      *
149      * @return  A new datagram channel
150      *
151      * @throws  IOException
152      *          If an I/O error occurs
153      *
154      * @see     <a href="../../net/doc-files/net-properties.html#Ipv4IPv6">
155      *          java.net.preferIPv4Stack</a> system property
156      */
157     public static DatagramChannel open() throws IOException {
158         return SelectorProvider.provider().openDatagramChannel();
159     }
160 
161     /**
162      * Opens a datagram channel.
163      *
164      * <p> The {@code family} parameter is used to specify the {@link
165      * ProtocolFamily}. If the datagram channel is to be used for IP multicasting
166      * then this should correspond to the address type of the multicast groups
167      * that this channel will join.
168      *
169      * <p> The new channel is created by invoking the {@link
170      * java.nio.channels.spi.SelectorProvider#openDatagramChannel(ProtocolFamily)
171      * openDatagramChannel} method of the system-wide default {@link
172      * java.nio.channels.spi.SelectorProvider} object.  The channel will not be
173      * connected.
174      *
175      * @apiNote <a href="package-summary.html#unixdomain">Unix domain</a> sockets
176      * are not supported by DatagramChannel.
177      *
178      * @param   family
179      *          The protocol family
180      *
181      * @return  A new datagram channel
182      *
183      * @throws  UnsupportedOperationException
184      *          If the specified protocol family is not supported. For example,
185      *          suppose the parameter is specified as {@link
186      *          java.net.StandardProtocolFamily#INET6 StandardProtocolFamily.INET6}
187      *          but IPv6 is not enabled on the platform.
188      * @throws  IOException
189      *          If an I/O error occurs
190      *
191      * @see     <a href="../../net/doc-files/net-properties.html#Ipv4IPv6">
192      *          java.net.preferIPv4Stack</a> system property
193      *
194      * @since   1.7
195      */
196     public static DatagramChannel open(ProtocolFamily family) throws IOException {
197         return SelectorProvider.provider().openDatagramChannel(requireNonNull(family));
198     }
199 
200     /**
201      * Returns an operation set identifying this channel's supported
202      * operations.
203      *
204      * <p> Datagram channels support reading and writing, so this method
205      * returns {@code (}{@link SelectionKey#OP_READ} {@code |}&nbsp;{@link
206      * SelectionKey#OP_WRITE}{@code )}.
207      *
208      * @return  The valid-operation set
209      */
210     public final int validOps() {
211         return (SelectionKey.OP_READ
212                 | SelectionKey.OP_WRITE);
213     }

621     /**
622      * {@inheritDoc}
623      * <p>
624      * If there is a security manager set, its {@code checkConnect} method is
625      * called with the local address and {@code -1} as its arguments to see
626      * if the operation is allowed. If the operation is not allowed,
627      * a {@code SocketAddress} representing the
628      * {@link java.net.InetAddress#getLoopbackAddress loopback} address and the
629      * local port of the channel's socket is returned.
630      *
631      * @return  The {@code SocketAddress} that the socket is bound to, or the
632      *          {@code SocketAddress} representing the loopback address if
633      *          denied by the security manager, or {@code null} if the
634      *          channel's socket is not bound
635      *
636      * @throws  ClosedChannelException     {@inheritDoc}
637      * @throws  IOException                {@inheritDoc}
638      */
639     @Override
640     public abstract SocketAddress getLocalAddress() throws IOException;

641 }
< prev index next >