< prev index next >

src/java.base/share/classes/java/net/DatagramSocket.java

Print this page


   1 /*
   2  * Copyright (c) 1995, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


1291      * @see       SecurityManager#checkSetFactory
1292      * @since 1.3
1293      */
1294     public static synchronized void
1295     setDatagramSocketImplFactory(DatagramSocketImplFactory fac)
1296        throws IOException
1297     {
1298         if (factory != null) {
1299             throw new SocketException("factory already defined");
1300         }
1301         SecurityManager security = System.getSecurityManager();
1302         if (security != null) {
1303             security.checkSetFactory();
1304         }
1305         factory = fac;
1306     }
1307 
1308     /**
1309      * Sets the value of a socket option.
1310      *

1311      * @param name The socket option
1312      * @param value The value of the socket option. A value of {@code null}
1313      *              may be valid for some options.
1314      *
1315      * @return this DatagramSocket
1316      *
1317      * @throws UnsupportedOperationException if the datagram socket
1318      *         does not support the option.
1319      *
1320      * @throws IllegalArgumentException if the value is not valid for
1321      *         the option.
1322      *
1323      * @throws IOException if an I/O error occurs, or if the socket is closed.
1324      *
1325      * @throws SecurityException if a security manager is set and if the socket
1326      *         option requires a security permission and if the caller does
1327      *         not have the required permission.
1328      *         {@link java.net.StandardSocketOptions StandardSocketOptions}
1329      *         do not require any security permission.
1330      *
1331      * @throws NullPointerException if name is {@code null}
1332      *
1333      * @since 1.9
1334      */
1335     public <T> DatagramSocket setOption(SocketOption<T> name, T value)
1336         throws IOException
1337     {
1338         getImpl().setOption(name, value);
1339         return this;
1340     }
1341 
1342     /**
1343      * Returns the value of a socket option.
1344      *

1345      * @param name The socket option
1346      *
1347      * @return The value of the socket option.
1348      *
1349      * @throws UnsupportedOperationException if the datagram socket
1350      *         does not support the option.
1351      *
1352      * @throws IOException if an I/O error occurs, or if the socket is closed.
1353      *
1354      * @throws NullPointerException if name is {@code null}
1355      *
1356      * @throws SecurityException if a security manager is set and if the socket
1357      *         option requires a security permission and if the caller does
1358      *         not have the required permission.
1359      *         {@link java.net.StandardSocketOptions StandardSocketOptions}
1360      *         do not require any security permission.
1361      *
1362      * @since 1.9
1363      */
1364     public <T> T getOption(SocketOption<T> name) throws IOException {


   1 /*
   2  * Copyright (c) 1995, 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


1291      * @see       SecurityManager#checkSetFactory
1292      * @since 1.3
1293      */
1294     public static synchronized void
1295     setDatagramSocketImplFactory(DatagramSocketImplFactory fac)
1296        throws IOException
1297     {
1298         if (factory != null) {
1299             throw new SocketException("factory already defined");
1300         }
1301         SecurityManager security = System.getSecurityManager();
1302         if (security != null) {
1303             security.checkSetFactory();
1304         }
1305         factory = fac;
1306     }
1307 
1308     /**
1309      * Sets the value of a socket option.
1310      *
1311      * @param <T> The type of the socket option value
1312      * @param name The socket option
1313      * @param value The value of the socket option. A value of {@code null}
1314      *              may be valid for some options.
1315      *
1316      * @return this DatagramSocket
1317      *
1318      * @throws UnsupportedOperationException if the datagram socket
1319      *         does not support the option.
1320      *
1321      * @throws IllegalArgumentException if the value is not valid for
1322      *         the option.
1323      *
1324      * @throws IOException if an I/O error occurs, or if the socket is closed.
1325      *
1326      * @throws SecurityException if a security manager is set and if the socket
1327      *         option requires a security permission and if the caller does
1328      *         not have the required permission.
1329      *         {@link java.net.StandardSocketOptions StandardSocketOptions}
1330      *         do not require any security permission.
1331      *
1332      * @throws NullPointerException if name is {@code null}
1333      *
1334      * @since 1.9
1335      */
1336     public <T> DatagramSocket setOption(SocketOption<T> name, T value)
1337         throws IOException
1338     {
1339         getImpl().setOption(name, value);
1340         return this;
1341     }
1342 
1343     /**
1344      * Returns the value of a socket option.
1345      *
1346      * @param <T> The type of the socket option value
1347      * @param name The socket option
1348      *
1349      * @return The value of the socket option.
1350      *
1351      * @throws UnsupportedOperationException if the datagram socket
1352      *         does not support the option.
1353      *
1354      * @throws IOException if an I/O error occurs, or if the socket is closed.
1355      *
1356      * @throws NullPointerException if name is {@code null}
1357      *
1358      * @throws SecurityException if a security manager is set and if the socket
1359      *         option requires a security permission and if the caller does
1360      *         not have the required permission.
1361      *         {@link java.net.StandardSocketOptions StandardSocketOptions}
1362      *         do not require any security permission.
1363      *
1364      * @since 1.9
1365      */
1366     public <T> T getOption(SocketOption<T> name) throws IOException {


< prev index next >