25
25
26
26
package jdk .net ;
27
27
28
- import java .net .*;
28
+ import jdk .net .ExtendedSocketOptions .PlatformSocketOptions ;
29
+
29
30
import java .io .IOException ;
31
+ import java .net .DatagramSocket ;
32
+ import java .net .MulticastSocket ;
33
+ import java .net .ServerSocket ;
34
+ import java .net .Socket ;
35
+ import java .net .SocketOption ;
36
+ import java .net .StandardSocketOptions ;
30
37
import java .util .Collections ;
31
38
import java .util .HashMap ;
32
39
import java .util .HashSet ;
33
40
import java .util .Map ;
34
41
import java .util .Set ;
35
- import jdk .net .ExtendedSocketOptions .PlatformSocketOptions ;
36
42
37
43
/**
38
44
* Defines static methods to set and get socket options defined by the
50
56
* The details are specified in {@link ExtendedSocketOptions}. No permission
51
57
* is required for {@link java.net.StandardSocketOptions}.
52
58
*
59
+ * @deprecated
60
+ * Java SE 9 added standard methods to set/get socket options, and retrieve the per-Socket
61
+ * supported options effectively rendering this API redundant. Please refer to the corresponding
62
+ * socket's class for the equivalent method to set/get a socket option or retrieve available socket options.
63
+ *
53
64
* @see java.nio.channels.NetworkChannel
54
65
*/
66
+ @ Deprecated (since = "16" )
55
67
public class Sockets {
56
68
57
69
private static final Map <Class <?>,Set <SocketOption <?>>>
@@ -80,8 +92,11 @@ private Sockets() {}
80
92
*
81
93
* @throws NullPointerException if name is null
82
94
*
95
+ * @deprecated use {@link java.net.Socket#setOption(SocketOption, Object)} instead.
96
+ *
83
97
* @see java.net.StandardSocketOptions
84
98
*/
99
+ @ Deprecated (since = "16" )
85
100
public static <T > void setOption (Socket s , SocketOption <T > name , T value ) throws IOException
86
101
{
87
102
s .setOption (name , value );
@@ -105,8 +120,11 @@ public static <T> void setOption(Socket s, SocketOption<T> name, T value) throws
105
120
*
106
121
* @throws NullPointerException if name is null
107
122
*
123
+ * @deprecated use {@link java.net.Socket#getOption(SocketOption)} instead.
124
+ *
108
125
* @see java.net.StandardSocketOptions
109
126
*/
127
+ @ Deprecated (since = "16" )
110
128
public static <T > T getOption (Socket s , SocketOption <T > name ) throws IOException
111
129
{
112
130
return s .getOption (name );
@@ -132,8 +150,11 @@ public static <T> T getOption(Socket s, SocketOption<T> name) throws IOException
132
150
* @throws SecurityException if a security manager is set and the
133
151
* caller does not have any required permission.
134
152
*
153
+ * @deprecated use {@link java.net.ServerSocket#setOption(SocketOption, Object)} instead.
154
+ *
135
155
* @see java.net.StandardSocketOptions
136
156
*/
157
+ @ Deprecated (since = "16" )
137
158
public static <T > void setOption (ServerSocket s , SocketOption <T > name , T value ) throws IOException
138
159
{
139
160
s .setOption (name , value );
@@ -157,8 +178,11 @@ public static <T> void setOption(ServerSocket s, SocketOption<T> name, T value)
157
178
* @throws SecurityException if a security manager is set and the
158
179
* caller does not have any required permission.
159
180
*
181
+ * @deprecated use {@link java.net.ServerSocket#getOption(SocketOption)} instead.
182
+ *
160
183
* @see java.net.StandardSocketOptions
161
184
*/
185
+ @ Deprecated (since = "16" )
162
186
public static <T > T getOption (ServerSocket s , SocketOption <T > name ) throws IOException
163
187
{
164
188
return s .getOption (name );
@@ -185,8 +209,11 @@ public static <T> T getOption(ServerSocket s, SocketOption<T> name) throws IOExc
185
209
* @throws SecurityException if a security manager is set and the
186
210
* caller does not have any required permission.
187
211
*
212
+ * @deprecated use {@link java.net.DatagramSocket#setOption(SocketOption, Object)} instead.
213
+ *
188
214
* @see java.net.StandardSocketOptions
189
215
*/
216
+ @ Deprecated (since = "16" )
190
217
public static <T > void setOption (DatagramSocket s , SocketOption <T > name , T value ) throws IOException
191
218
{
192
219
s .setOption (name , value );
@@ -211,8 +238,11 @@ public static <T> void setOption(DatagramSocket s, SocketOption<T> name, T value
211
238
* @throws SecurityException if a security manager is set and the
212
239
* caller does not have any required permission.
213
240
*
241
+ * @deprecated use {@link java.net.DatagramSocket#getOption(SocketOption)} instead.
242
+ *
214
243
* @see java.net.StandardSocketOptions
215
244
*/
245
+ @ Deprecated (since = "16" )
216
246
public static <T > T getOption (DatagramSocket s , SocketOption <T > name ) throws IOException
217
247
{
218
248
return s .getOption (name );
@@ -227,7 +257,11 @@ public static <T> T getOption(DatagramSocket s, SocketOption<T> name) throws IOE
227
257
*
228
258
* @throws IllegalArgumentException if socketType is not a valid
229
259
* socket type from the java.net package.
260
+ *
261
+ * @deprecated use {@link Socket#supportedOptions()}, {@link ServerSocket#supportedOptions()},
262
+ * or {@link DatagramSocket#supportedOptions()} instead.
230
263
*/
264
+ @ Deprecated (since = "16" , forRemoval =true )
231
265
public static Set <SocketOption <?>> supportedOptions (Class <?> socketType ) {
232
266
Set <SocketOption <?>> set = options .get (socketType );
233
267
if (set == null ) {
0 commit comments