< prev index next >

src/java.base/share/classes/sun/nio/ch/SocketAdaptor.java

Print this page

 48 // The methods in this class are defined in exactly the same order as in
 49 // java.net.Socket so as to simplify tracking future changes to that class.
 50 //
 51 
 52 class SocketAdaptor
 53     extends Socket
 54 {
 55     // The channel being adapted
 56     private final SocketChannelImpl sc;
 57 
 58     // Timeout "option" value for reads
 59     private volatile int timeout;
 60 
 61     private SocketAdaptor(SocketChannelImpl sc) throws SocketException {
 62         super(DummySocketImpl.create());
 63         this.sc = sc;
 64     }
 65 
 66     @SuppressWarnings("removal")
 67     static Socket create(SocketChannelImpl sc) {
 68         PrivilegedExceptionAction<Socket> pa = () -> new SocketAdaptor(sc);
 69         try {
 70             return AccessController.doPrivileged(pa);
 71         } catch (PrivilegedActionException pae) {
 72             throw new InternalError("Should not reach here", pae);





 73         }
 74     }
 75 
 76     private InetSocketAddress localAddress() {
 77         return (InetSocketAddress) sc.localAddress();
 78     }
 79 
 80     private InetSocketAddress remoteAddress() {
 81         return (InetSocketAddress) sc.remoteAddress();
 82     }
 83 
 84     @Override
 85     public void connect(SocketAddress remote) throws IOException {
 86         connect(remote, 0);
 87     }
 88 
 89     @Override
 90     public void connect(SocketAddress remote, int timeout) throws IOException {
 91         if (remote == null)
 92             throw new IllegalArgumentException("connect: The address can't be null");

 48 // The methods in this class are defined in exactly the same order as in
 49 // java.net.Socket so as to simplify tracking future changes to that class.
 50 //
 51 
 52 class SocketAdaptor
 53     extends Socket
 54 {
 55     // The channel being adapted
 56     private final SocketChannelImpl sc;
 57 
 58     // Timeout "option" value for reads
 59     private volatile int timeout;
 60 
 61     private SocketAdaptor(SocketChannelImpl sc) throws SocketException {
 62         super(DummySocketImpl.create());
 63         this.sc = sc;
 64     }
 65 
 66     @SuppressWarnings("removal")
 67     static Socket create(SocketChannelImpl sc) {

 68         try {
 69             if (System.getSecurityManager() == null) {
 70                 return new SocketAdaptor(sc);
 71             } else {
 72                 PrivilegedExceptionAction<Socket> pa = () -> new SocketAdaptor(sc);
 73                 return AccessController.doPrivileged(pa);
 74             }
 75         } catch (SocketException | PrivilegedActionException e) {
 76             throw new InternalError(e);
 77         }
 78     }
 79 
 80     private InetSocketAddress localAddress() {
 81         return (InetSocketAddress) sc.localAddress();
 82     }
 83 
 84     private InetSocketAddress remoteAddress() {
 85         return (InetSocketAddress) sc.remoteAddress();
 86     }
 87 
 88     @Override
 89     public void connect(SocketAddress remote) throws IOException {
 90         connect(remote, 0);
 91     }
 92 
 93     @Override
 94     public void connect(SocketAddress remote, int timeout) throws IOException {
 95         if (remote == null)
 96             throw new IllegalArgumentException("connect: The address can't be null");
< prev index next >