Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/java.base/share/classes/java/nio/channels/SocketChannel.java
41159 views
1
/*
2
* Copyright (c) 2000, 2020, 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
23
* questions.
24
*/
25
26
package java.nio.channels;
27
28
import java.io.IOException;
29
import java.net.InetSocketAddress;
30
import java.net.NetPermission;
31
import java.net.ProtocolFamily;
32
import java.net.StandardProtocolFamily;
33
import java.net.Socket;
34
import java.net.SocketOption;
35
import java.net.SocketAddress;
36
import java.net.UnixDomainSocketAddress;
37
import java.nio.ByteBuffer;
38
import java.nio.channels.spi.AbstractSelectableChannel;
39
import java.nio.channels.spi.SelectorProvider;
40
import static java.util.Objects.requireNonNull;
41
42
/**
43
* A selectable channel for stream-oriented connecting sockets.
44
*
45
* <p> A socket channel is created by invoking one of the {@code open} methods of
46
* this class. The no-arg {@link #open() open} method opens a socket channel
47
* for an <i>Internet protocol</i> socket. The {@link #open(ProtocolFamily)}
48
* method is used to open a socket channel for a socket of a specified protocol
49
* family. It is not possible to create a channel for an arbitrary, pre-existing
50
* socket. A newly-created socket channel is open but not yet connected. An
51
* attempt to invoke an I/O operation upon an unconnected channel will cause a
52
* {@link NotYetConnectedException} to be thrown. A socket channel can be
53
* connected by invoking its {@link #connect connect} method; once connected,
54
* a socket channel remains connected until it is closed. Whether or not a
55
* socket channel is connected may be determined by invoking its {@link #isConnected()
56
* isConnected} method.
57
*
58
* <p> Socket channels support <i>non-blocking connection:</i>&nbsp;A socket
59
* channel may be created and the process of establishing the link to the
60
* remote socket may be initiated via the {@link #connect connect} method for
61
* later completion by the {@link #finishConnect finishConnect} method.
62
* Whether or not a connection operation is in progress may be determined by
63
* invoking the {@link #isConnectionPending isConnectionPending} method.
64
*
65
* <p> Socket channels support <i>asynchronous shutdown</i>, which is similar
66
* to the asynchronous close operation specified in the {@link Channel} class.
67
* If the input side of a socket is shut down by one thread while another
68
* thread is blocked in a read operation on the socket's channel, then the read
69
* operation in the blocked thread will complete without reading any bytes and
70
* will return {@code -1}. If the output side of a socket is shut down by one
71
* thread while another thread is blocked in a write operation on the socket's
72
* channel, then the blocked thread will receive an {@link
73
* AsynchronousCloseException}.
74
*
75
* <p> Socket options are configured using the {@link #setOption(SocketOption,Object)
76
* setOption} method. Socket channels for <i>Internet protocol</i> sockets support
77
* following options:
78
* <blockquote>
79
* <table class="striped">
80
* <caption style="display:none">Socket options</caption>
81
* <thead>
82
* <tr>
83
* <th scope="col">Option Name</th>
84
* <th scope="col">Description</th>
85
* </tr>
86
* </thead>
87
* <tbody>
88
* <tr>
89
* <th scope="row"> {@link java.net.StandardSocketOptions#SO_SNDBUF SO_SNDBUF} </th>
90
* <td> The size of the socket send buffer </td>
91
* </tr>
92
* <tr>
93
* <th scope="row"> {@link java.net.StandardSocketOptions#SO_RCVBUF SO_RCVBUF} </th>
94
* <td> The size of the socket receive buffer </td>
95
* </tr>
96
* <tr>
97
* <th scope="row"> {@link java.net.StandardSocketOptions#SO_KEEPALIVE SO_KEEPALIVE} </th>
98
* <td> Keep connection alive </td>
99
* </tr>
100
* <tr>
101
* <th scope="row"> {@link java.net.StandardSocketOptions#SO_REUSEADDR SO_REUSEADDR} </th>
102
* <td> Re-use address </td>
103
* </tr>
104
* <tr>
105
* <th scope="row"> {@link java.net.StandardSocketOptions#SO_LINGER SO_LINGER} </th>
106
* <td> Linger on close if data is present (when configured in blocking mode
107
* only) </td>
108
* </tr>
109
* <tr>
110
* <th scope="row"> {@link java.net.StandardSocketOptions#TCP_NODELAY TCP_NODELAY} </th>
111
* <td> Disable the Nagle algorithm </td>
112
* </tr>
113
* </tbody>
114
* </table>
115
* </blockquote>
116
*
117
* <p> Socket channels for <i>Unix domain</i> sockets support:
118
* <blockquote>
119
* <table class="striped">
120
* <caption style="display:none">Socket options</caption>
121
* <thead>
122
* <tr>
123
* <th scope="col">Option Name</th>
124
* <th scope="col">Description</th>
125
* </tr>
126
* </thead>
127
* <tbody>
128
* <tr>
129
* <th scope="row"> {@link java.net.StandardSocketOptions#SO_SNDBUF SO_SNDBUF} </th>
130
* <td> The size of the socket send buffer </td>
131
* </tr>
132
* <tr>
133
* <th scope="row"> {@link java.net.StandardSocketOptions#SO_RCVBUF SO_RCVBUF} </th>
134
* <td> The size of the socket receive buffer </td>
135
* </tr>
136
* <tr>
137
* <th scope="row"> {@link java.net.StandardSocketOptions#SO_LINGER SO_LINGER} </th>
138
* <td> Linger on close if data is present (when configured in blocking mode
139
* only) </td>
140
* </tr>
141
* </tbody>
142
* </table>
143
* </blockquote>
144
*
145
* <p> Additional (implementation specific) options may also be supported.
146
*
147
* <p> Socket channels are safe for use by multiple concurrent threads. They
148
* support concurrent reading and writing, though at most one thread may be
149
* reading and at most one thread may be writing at any given time. The {@link
150
* #connect connect} and {@link #finishConnect finishConnect} methods are
151
* mutually synchronized against each other, and an attempt to initiate a read
152
* or write operation while an invocation of one of these methods is in
153
* progress will block until that invocation is complete. </p>
154
*
155
* @author Mark Reinhold
156
* @author JSR-51 Expert Group
157
* @since 1.4
158
*/
159
160
public abstract class SocketChannel
161
extends AbstractSelectableChannel
162
implements ByteChannel, ScatteringByteChannel, GatheringByteChannel, NetworkChannel
163
{
164
165
/**
166
* Initializes a new instance of this class.
167
*
168
* @param provider
169
* The provider that created this channel
170
*/
171
protected SocketChannel(SelectorProvider provider) {
172
super(provider);
173
}
174
175
/**
176
* Opens a socket channel for an <i>Internet protocol</i> socket.
177
*
178
* <p> The new channel is created by invoking the {@link
179
* java.nio.channels.spi.SelectorProvider#openSocketChannel
180
* openSocketChannel} method of the system-wide default {@link
181
* java.nio.channels.spi.SelectorProvider} object. </p>
182
*
183
* @return A new socket channel
184
*
185
* @throws IOException
186
* If an I/O error occurs
187
*
188
* @see <a href="../../net/doc-files/net-properties.html#Ipv4IPv6">
189
* java.net.preferIPv4Stack</a> system property
190
*/
191
public static SocketChannel open() throws IOException {
192
return SelectorProvider.provider().openSocketChannel();
193
}
194
195
/**
196
* Opens a socket channel. The {@code family} parameter specifies the
197
* {@link ProtocolFamily protocol family} of the channel's socket.
198
*
199
* <p> The new channel is created by invoking the {@link
200
* java.nio.channels.spi.SelectorProvider#openSocketChannel(ProtocolFamily)
201
* openSocketChannel(ProtocolFamily)} method of the system-wide default.
202
* {@link java.nio.channels.spi.SelectorProvider} object.</p>
203
*
204
* @param family
205
* The protocol family
206
*
207
* @return A new socket channel
208
*
209
* @throws UnsupportedOperationException
210
* If the specified protocol family is not supported. For example,
211
* suppose the parameter is specified as {@link
212
* java.net.StandardProtocolFamily#INET6 StandardProtocolFamily.INET6}
213
* but IPv6 is not enabled on the platform.
214
* @throws IOException
215
* If an I/O error occurs
216
*
217
* @see <a href="../../net/doc-files/net-properties.html#Ipv4IPv6">
218
* java.net.preferIPv4Stack</a> system property
219
*
220
* @since 15
221
*/
222
public static SocketChannel open(ProtocolFamily family) throws IOException {
223
return SelectorProvider.provider().openSocketChannel(requireNonNull(family));
224
}
225
226
/**
227
* Opens a socket channel and connects it to a remote address.
228
*
229
* <p> If the remote address is an {@link InetSocketAddress} then this
230
* method works as if by invoking the {@link #open()} method, invoking the
231
* {@link #connect(SocketAddress) connect} method upon the resulting socket
232
* channel, passing it {@code remote}, and then returning that channel.
233
*
234
* <p> If the remote address is a {@link UnixDomainSocketAddress} then this
235
* works by invoking the {@link #open(ProtocolFamily)} method with {@link
236
* StandardProtocolFamily#UNIX} as parameter, invoking the {@link
237
* #connect(SocketAddress) connect} method upon the resulting socket channel,
238
* passing it {@code remote}, then returning that channel. </p>
239
*
240
* @param remote
241
* The remote address to which the new channel is to be connected
242
*
243
* @return A new, and connected, socket channel
244
*
245
* @throws AsynchronousCloseException
246
* If another thread closes this channel
247
* while the connect operation is in progress
248
*
249
* @throws ClosedByInterruptException
250
* If another thread interrupts the current thread
251
* while the connect operation is in progress, thereby
252
* closing the channel and setting the current thread's
253
* interrupt status
254
*
255
* @throws UnresolvedAddressException
256
* If the given remote address is an InetSocketAddress that is not fully
257
* resolved
258
*
259
* @throws UnsupportedAddressTypeException
260
* If the type of the given remote address is not supported
261
*
262
* @throws SecurityException
263
* If a security manager has been installed
264
* and it does not permit access to the given remote endpoint
265
*
266
* @throws IOException
267
* If some other I/O error occurs
268
*
269
* @see <a href="../../net/doc-files/net-properties.html#Ipv4IPv6">
270
* java.net.preferIPv4Stack</a> system property
271
*/
272
public static SocketChannel open(SocketAddress remote)
273
throws IOException
274
{
275
SocketChannel sc;
276
requireNonNull(remote);
277
if (remote instanceof InetSocketAddress)
278
sc = open();
279
else if (remote instanceof UnixDomainSocketAddress)
280
sc = open(StandardProtocolFamily.UNIX);
281
else
282
throw new UnsupportedAddressTypeException();
283
284
try {
285
sc.connect(remote);
286
} catch (Throwable x) {
287
try {
288
sc.close();
289
} catch (Throwable suppressed) {
290
x.addSuppressed(suppressed);
291
}
292
throw x;
293
}
294
assert sc.isConnected();
295
return sc;
296
}
297
298
/**
299
* Returns an operation set identifying this channel's supported
300
* operations.
301
*
302
* <p> Socket channels support connecting, reading, and writing, so this
303
* method returns {@code (}{@link SelectionKey#OP_CONNECT}
304
* {@code |}&nbsp;{@link SelectionKey#OP_READ} {@code |}&nbsp;{@link
305
* SelectionKey#OP_WRITE}{@code )}.
306
*
307
* @return The valid-operation set
308
*/
309
public final int validOps() {
310
return (SelectionKey.OP_READ
311
| SelectionKey.OP_WRITE
312
| SelectionKey.OP_CONNECT);
313
}
314
315
316
// -- Socket-specific operations --
317
318
/**
319
* Binds the channel's socket to a local address.
320
*
321
* <p> This method is used to establish an association between the socket
322
* and a local address. For <i>Internet Protocol</i> sockets, once an
323
* association is established then the socket remains bound until the
324
* channel is closed. If the {@code local} parameter has the value {@code
325
* null} then the socket will be bound to an address that is assigned
326
* automatically.
327
*
328
* @apiNote
329
* Binding a socket channel to a <i>Unix Domain</i> socket creates a file
330
* corresponding to the file path in the {@link UnixDomainSocketAddress}. This
331
* file persists after the channel is closed, and must be removed before
332
* another socket can bind to the same name. If a socket channel to a Unix
333
* Domain socket is <i>implicitly</i> bound by connecting it without calling
334
* bind first, then its socket is
335
* <a href="../../../java/net/UnixDomainSocketAddress.html#unnamed">unnamed</a>
336
* with no corresponding socket file in the file-system. If a socket channel
337
* to a Unix Domain socket is <i>automatically</i> bound by calling {@code
338
* bind(null)} this results in an unnamed socket also.
339
*
340
* @implNote
341
* Each platform enforces an implementation specific maximum length for the
342
* name of a <i>Unix Domain</i> socket. This limitation is enforced when a
343
* channel is bound. The maximum length is typically close to and generally
344
* not less than 100 bytes.
345
*
346
* @param local The address to bind the socket, or {@code null} to bind
347
* the socket to an automatically assigned socket address
348
*
349
* @return This channel
350
*
351
* @throws ConnectionPendingException
352
* If a non-blocking connect operation is already in progress on
353
* this channel
354
* @throws AlreadyBoundException {@inheritDoc}
355
* @throws UnsupportedAddressTypeException {@inheritDoc}
356
* @throws ClosedChannelException {@inheritDoc}
357
* @throws IOException {@inheritDoc}
358
* @throws SecurityException
359
* If a security manager has been installed and its {@link
360
* SecurityManager#checkListen checkListen} method denies
361
* the operation for an <i>Internet protocol</i> socket address,
362
* or for a <i>Unix domain</i> socket address if it denies
363
* {@link NetPermission}{@code("accessUnixDomainSocket")}.
364
*
365
* @since 1.7
366
*/
367
@Override
368
public abstract SocketChannel bind(SocketAddress local)
369
throws IOException;
370
371
/**
372
* @throws UnsupportedOperationException {@inheritDoc}
373
* @throws IllegalArgumentException {@inheritDoc}
374
* @throws ClosedChannelException {@inheritDoc}
375
* @throws IOException {@inheritDoc}
376
*
377
* @since 1.7
378
*/
379
@Override
380
public abstract <T> SocketChannel setOption(SocketOption<T> name, T value)
381
throws IOException;
382
383
/**
384
* Shutdown the connection for reading without closing the channel.
385
*
386
* <p> Once shutdown for reading then further reads on the channel will
387
* return {@code -1}, the end-of-stream indication. If the input side of the
388
* connection is already shutdown then invoking this method has no effect.
389
*
390
* @return The channel
391
*
392
* @throws NotYetConnectedException
393
* If this channel is not yet connected
394
* @throws ClosedChannelException
395
* If this channel is closed
396
* @throws IOException
397
* If some other I/O error occurs
398
*
399
* @since 1.7
400
*/
401
public abstract SocketChannel shutdownInput() throws IOException;
402
403
/**
404
* Shutdown the connection for writing without closing the channel.
405
*
406
* <p> Once shutdown for writing then further attempts to write to the
407
* channel will throw {@link ClosedChannelException}. If the output side of
408
* the connection is already shutdown then invoking this method has no
409
* effect.
410
*
411
* @return The channel
412
*
413
* @throws NotYetConnectedException
414
* If this channel is not yet connected
415
* @throws ClosedChannelException
416
* If this channel is closed
417
* @throws IOException
418
* If some other I/O error occurs
419
*
420
* @since 1.7
421
*/
422
public abstract SocketChannel shutdownOutput() throws IOException;
423
424
/**
425
* Retrieves a socket associated with this channel.
426
*
427
* @return A socket associated with this channel
428
*
429
* @throws UnsupportedOperationException
430
* If the channel's socket is not an <i>Internet protocol</i> socket
431
*/
432
public abstract Socket socket();
433
434
/**
435
* Tells whether or not this channel's network socket is connected.
436
*
437
* @return {@code true} if, and only if, this channel's network socket
438
* is {@link #isOpen open} and connected
439
*/
440
public abstract boolean isConnected();
441
442
/**
443
* Tells whether or not a connection operation is in progress on this
444
* channel.
445
*
446
* @return {@code true} if, and only if, a connection operation has been
447
* initiated on this channel but not yet completed by invoking the
448
* {@link #finishConnect finishConnect} method
449
*/
450
public abstract boolean isConnectionPending();
451
452
/**
453
* Connects this channel's socket.
454
*
455
* <p> If this channel is in non-blocking mode then an invocation of this
456
* method initiates a non-blocking connection operation. If the connection
457
* is established immediately, as can happen with a local connection, then
458
* this method returns {@code true}. Otherwise this method returns
459
* {@code false} and the connection operation must later be completed by
460
* invoking the {@link #finishConnect finishConnect} method.
461
*
462
* <p> If this channel is in blocking mode then an invocation of this
463
* method will block until the connection is established or an I/O error
464
* occurs.
465
*
466
* <p> For channels to <i>Internet protocol</i> sockets, this method performs
467
* exactly the same security checks as the {@link java.net.Socket} class.
468
* That is, if a security manager has been
469
* installed then this method verifies that its {@link
470
* java.lang.SecurityManager#checkConnect checkConnect} method permits
471
* connecting to the address and port number of the given remote endpoint.
472
*
473
* <p> For channels to <i>Unix Domain</i> sockets, this method checks
474
* {@link java.net.NetPermission NetPermission}{@code
475
* ("accessUnixDomainSocket")} with the security manager's {@link
476
* SecurityManager#checkPermission(java.security.Permission)
477
* checkPermission} method.
478
*
479
* <p> This method may be invoked at any time. If a read or write
480
* operation upon this channel is invoked while an invocation of this
481
* method is in progress then that operation will first block until this
482
* invocation is complete. If a connection attempt is initiated but fails,
483
* that is, if an invocation of this method throws a checked exception,
484
* then the channel will be closed. </p>
485
*
486
* @param remote
487
* The remote address to which this channel is to be connected
488
*
489
* @return {@code true} if a connection was established,
490
* {@code false} if this channel is in non-blocking mode
491
* and the connection operation is in progress
492
*
493
* @throws AlreadyConnectedException
494
* If this channel is already connected
495
*
496
* @throws ConnectionPendingException
497
* If a non-blocking connection operation is already in progress
498
* on this channel
499
*
500
* @throws ClosedChannelException
501
* If this channel is closed
502
*
503
* @throws AsynchronousCloseException
504
* If another thread closes this channel
505
* while the connect operation is in progress
506
*
507
* @throws ClosedByInterruptException
508
* If another thread interrupts the current thread
509
* while the connect operation is in progress, thereby
510
* closing the channel and setting the current thread's
511
* interrupt status
512
*
513
* @throws UnresolvedAddressException
514
* If the given remote address is an InetSocketAddress that is not fully resolved
515
*
516
* @throws UnsupportedAddressTypeException
517
* If the type of the given remote address is not supported
518
*
519
* @throws SecurityException
520
* If a security manager has been installed
521
* and it does not permit access to the given remote endpoint
522
*
523
* @throws IOException
524
* If some other I/O error occurs
525
*/
526
public abstract boolean connect(SocketAddress remote) throws IOException;
527
528
/**
529
* Finishes the process of connecting a socket channel.
530
*
531
* <p> A non-blocking connection operation is initiated by placing a socket
532
* channel in non-blocking mode and then invoking its {@link #connect
533
* connect} method. Once the connection is established, or the attempt has
534
* failed, the socket channel will become connectable and this method may
535
* be invoked to complete the connection sequence. If the connection
536
* operation failed then invoking this method will cause an appropriate
537
* {@link java.io.IOException} to be thrown.
538
*
539
* <p> If this channel is already connected then this method will not block
540
* and will immediately return {@code true}. If this channel is in
541
* non-blocking mode then this method will return {@code false} if the
542
* connection process is not yet complete. If this channel is in blocking
543
* mode then this method will block until the connection either completes
544
* or fails, and will always either return {@code true} or throw a checked
545
* exception describing the failure.
546
*
547
* <p> This method may be invoked at any time. If a read or write
548
* operation upon this channel is invoked while an invocation of this
549
* method is in progress then that operation will first block until this
550
* invocation is complete. If a connection attempt fails, that is, if an
551
* invocation of this method throws a checked exception, then the channel
552
* will be closed. </p>
553
*
554
* @return {@code true} if, and only if, this channel's socket is now
555
* connected
556
*
557
* @throws NoConnectionPendingException
558
* If this channel is not connected and a connection operation
559
* has not been initiated
560
*
561
* @throws ClosedChannelException
562
* If this channel is closed
563
*
564
* @throws AsynchronousCloseException
565
* If another thread closes this channel
566
* while the connect operation is in progress
567
*
568
* @throws ClosedByInterruptException
569
* If another thread interrupts the current thread
570
* while the connect operation is in progress, thereby
571
* closing the channel and setting the current thread's
572
* interrupt status
573
*
574
* @throws IOException
575
* If some other I/O error occurs
576
*/
577
public abstract boolean finishConnect() throws IOException;
578
579
/**
580
* Returns the remote address to which this channel's socket is connected.
581
*
582
* <p> Where the channel's socket is bound and connected to an <i>Internet
583
* Protocol</i> socket address then the return value is of type
584
* {@link java.net.InetSocketAddress}.
585
*
586
* <p> Where the channel's socket is bound and connected to a <i>Unix Domain</i>
587
* socket address, the returned address is a {@link UnixDomainSocketAddress}.
588
*
589
* @return The remote address; {@code null} if the channel's socket is not
590
* connected
591
*
592
* @throws ClosedChannelException
593
* If the channel is closed
594
* @throws IOException
595
* If an I/O error occurs
596
*
597
* @since 1.7
598
*/
599
public abstract SocketAddress getRemoteAddress() throws IOException;
600
601
// -- ByteChannel operations --
602
603
/**
604
* @throws NotYetConnectedException
605
* If this channel is not yet connected
606
*/
607
public abstract int read(ByteBuffer dst) throws IOException;
608
609
/**
610
* @throws NotYetConnectedException
611
* If this channel is not yet connected
612
*/
613
public abstract long read(ByteBuffer[] dsts, int offset, int length)
614
throws IOException;
615
616
/**
617
* @throws NotYetConnectedException
618
* If this channel is not yet connected
619
*/
620
public final long read(ByteBuffer[] dsts) throws IOException {
621
return read(dsts, 0, dsts.length);
622
}
623
624
/**
625
* @throws NotYetConnectedException
626
* If this channel is not yet connected
627
*/
628
public abstract int write(ByteBuffer src) throws IOException;
629
630
/**
631
* @throws NotYetConnectedException
632
* If this channel is not yet connected
633
*/
634
public abstract long write(ByteBuffer[] srcs, int offset, int length)
635
throws IOException;
636
637
/**
638
* @throws NotYetConnectedException
639
* If this channel is not yet connected
640
*/
641
public final long write(ByteBuffer[] srcs) throws IOException {
642
return write(srcs, 0, srcs.length);
643
}
644
645
/**
646
* {@inheritDoc}
647
*
648
* If there is a security manager set, its {@code checkConnect} method is
649
* called with the local address and {@code -1} as its arguments to see
650
* if the operation is allowed. If the operation is not allowed,
651
* a {@code SocketAddress} representing the
652
* {@link java.net.InetAddress#getLoopbackAddress loopback} address and the
653
* local port of the channel's socket is returned.
654
*
655
* <p> Where the channel is bound to a Unix Domain socket address, the socket
656
* address is a {@link UnixDomainSocketAddress}. If there is a security manager
657
* set, its {@link SecurityManager#checkPermission(java.security.Permission)
658
* checkPermission} method is called with {@link NetPermission}{@code
659
* ("accessUnixDomainSocket")}. If the operation is not allowed an unnamed
660
* {@link UnixDomainSocketAddress} is returned.
661
*
662
* @return The {@code SocketAddress} that the socket is bound to, or the
663
* {@code SocketAddress} representing the loopback address or empty
664
* path if denied by the security manager, or {@code null} if the
665
* channel's socket is not bound
666
*
667
* @throws ClosedChannelException {@inheritDoc}
668
* @throws IOException {@inheritDoc}
669
*/
670
@Override
671
public abstract SocketAddress getLocalAddress() throws IOException;
672
}
673
674