src/java.base/share/classes/java/net/DelegatingSocketImpl.java
author alanb
Mon, 11 Feb 2019 08:39:50 +0000
branchniosocketimpl-branch
changeset 57175 7eb6cdd1204a
parent 57172 63ab5af5d009
child 57176 726630bc6a4c
permissions -rw-r--r--
More cleanup. Also fix up jshell tests that depend on exception messages
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
57172
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
     1
/*
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
     2
 * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
     4
 *
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
    10
 *
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
    15
 * accompanied this code).
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
    16
 *
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
    20
 *
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
    23
 * questions.
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
    24
 */
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
    25
package java.net;
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
    26
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
    27
import java.io.FileDescriptor;
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
    28
import java.io.IOException;
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
    29
import java.io.InputStream;
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
    30
import java.io.OutputStream;
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
    31
import java.util.Objects;
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
    32
import java.util.Set;
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
    33
57175
7eb6cdd1204a More cleanup. Also fix up jshell tests that depend on exception messages
alanb
parents: 57172
diff changeset
    34
import sun.net.TrustedSocketImpl;
7eb6cdd1204a More cleanup. Also fix up jshell tests that depend on exception messages
alanb
parents: 57172
diff changeset
    35
57172
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
    36
/**
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
    37
 * A SocketImpl that delegates all methods to another SocketImpl.
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
    38
 */
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
    39
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
    40
class DelegatingSocketImpl extends SocketImpl {
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
    41
    protected final SocketImpl delegate;
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
    42
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
    43
    DelegatingSocketImpl(SocketImpl delegate) {
57175
7eb6cdd1204a More cleanup. Also fix up jshell tests that depend on exception messages
alanb
parents: 57172
diff changeset
    44
        assert delegate instanceof TrustedSocketImpl;
57172
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
    45
        this.delegate = Objects.requireNonNull(delegate);
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
    46
    }
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
    47
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
    48
    final SocketImpl delegate() {
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
    49
        return delegate;
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
    50
    }
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
    51
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
    52
    @Override
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
    53
    protected FileDescriptor getFileDescriptor() {
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
    54
        return delegate.getFileDescriptor();
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
    55
    }
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
    56
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
    57
    @Override
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
    58
    protected InetAddress getInetAddress() {
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
    59
        return delegate.getInetAddress();
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
    60
    }
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
    61
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
    62
    @Override
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
    63
    protected int getPort() {
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
    64
        return delegate.getPort();
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
    65
    }
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
    66
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
    67
    @Override
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
    68
    protected int getLocalPort() {
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
    69
        return delegate.getLocalPort();
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
    70
    }
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
    71
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
    72
    @Override
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
    73
    protected void create(boolean stream) throws IOException {
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
    74
        delegate.create(stream);
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
    75
    }
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
    76
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
    77
    @Override
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
    78
    protected void connect(String host, int port) throws IOException {
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
    79
        delegate.connect(host, port);
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
    80
    }
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
    81
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
    82
    @Override
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
    83
    protected void connect(InetAddress address, int port) throws IOException {
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
    84
        delegate.connect(address, port);
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
    85
    }
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
    86
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
    87
    @Override
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
    88
    protected void connect(SocketAddress address, int timeout) throws IOException {
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
    89
        delegate.connect(address, timeout);
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
    90
    }
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
    91
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
    92
    @Override
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
    93
    protected void bind(InetAddress host, int port) throws IOException {
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
    94
        delegate.bind(host, port);
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
    95
    }
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
    96
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
    97
    @Override
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
    98
    protected void listen(int backlog) throws IOException {
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
    99
        delegate.listen(backlog);
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
   100
    }
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
   101
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
   102
    @Override
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
   103
    protected void accept(SocketImpl s) throws IOException {
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
   104
        delegate.accept(s);
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
   105
    }
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
   106
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
   107
    @Override
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
   108
    protected InputStream getInputStream() throws IOException {
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
   109
        return delegate.getInputStream();
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
   110
    }
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
   111
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
   112
    @Override
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
   113
    protected OutputStream getOutputStream() throws IOException {
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
   114
        return delegate.getOutputStream();
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
   115
    }
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
   116
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
   117
    @Override
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
   118
    protected int available() throws IOException {
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
   119
        return delegate.available();
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
   120
    }
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
   121
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
   122
    @Override
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
   123
    protected void close() throws IOException {
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
   124
        delegate.close();
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
   125
    }
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
   126
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
   127
    @Override
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
   128
    protected boolean supportsUrgentData() {
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
   129
        return delegate.supportsUrgentData();
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
   130
    }
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
   131
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
   132
    @Override
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
   133
    protected void sendUrgentData(int data) throws IOException {
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
   134
        delegate.sendUrgentData(data);
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
   135
    }
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
   136
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
   137
    @Override
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
   138
    protected Set<SocketOption<?>> supportedOptions() {
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
   139
        return delegate.supportedOptions();
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
   140
    }
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
   141
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
   142
    @Override
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
   143
    protected <T> void setOption(SocketOption<T> opt, T value) throws IOException {
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
   144
        delegate.setOption(opt, value);
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
   145
    }
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
   146
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
   147
    @Override
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
   148
    protected <T> T getOption(SocketOption<T> opt) throws IOException {
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
   149
        return delegate.getOption(opt);
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
   150
    }
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
   151
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
   152
    @Override
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
   153
    public void setOption(int optID, Object value) throws SocketException {
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
   154
        delegate.setOption(optID, value);
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
   155
    }
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
   156
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
   157
    @Override
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
   158
    public Object getOption(int optID) throws SocketException {
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
   159
        return delegate.getOption(optID);
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
   160
    }
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
   161
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
   162
    @Override
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
   163
    protected void shutdownInput() throws IOException {
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
   164
        delegate.shutdownInput();
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
   165
    }
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
   166
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
   167
    @Override
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
   168
    protected void shutdownOutput() throws IOException {
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
   169
        delegate.shutdownOutput();
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
   170
    }
63ab5af5d009 Moving delegating SocketImpl to its own class
alanb
parents:
diff changeset
   171
}