Path: blob/master/src/java.base/share/classes/java/net/DelegatingSocketImpl.java
41152 views
/*1* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/24package java.net;2526import java.io.FileDescriptor;27import java.io.IOException;28import java.io.InputStream;29import java.io.OutputStream;30import java.util.Objects;31import java.util.Set;3233import sun.net.PlatformSocketImpl;3435/**36* A SocketImpl that delegates all methods to another SocketImpl.37*/3839class DelegatingSocketImpl extends SocketImpl {40protected final SocketImpl delegate;4142DelegatingSocketImpl(SocketImpl delegate) {43assert delegate instanceof PlatformSocketImpl;44this.delegate = Objects.requireNonNull(delegate);45}4647final SocketImpl delegate() {48return delegate;49}5051@Override52protected FileDescriptor getFileDescriptor() {53return delegate.getFileDescriptor();54}5556@Override57protected InetAddress getInetAddress() {58return delegate.getInetAddress();59}6061@Override62protected int getPort() {63return delegate.getPort();64}6566@Override67protected int getLocalPort() {68return delegate.getLocalPort();69}7071@Override72protected void create(boolean stream) throws IOException {73delegate.create(stream);74}7576@Override77protected void connect(String host, int port) throws IOException {78delegate.connect(host, port);79}8081@Override82protected void connect(InetAddress address, int port) throws IOException {83delegate.connect(address, port);84}8586@Override87protected void connect(SocketAddress address, int timeout) throws IOException {88delegate.connect(address, timeout);89}9091@Override92protected void bind(InetAddress host, int port) throws IOException {93delegate.bind(host, port);94}9596@Override97protected void listen(int backlog) throws IOException {98delegate.listen(backlog);99}100101@Override102protected void accept(SocketImpl s) throws IOException {103delegate.accept(s);104}105106@Override107protected InputStream getInputStream() throws IOException {108return delegate.getInputStream();109}110111@Override112protected OutputStream getOutputStream() throws IOException {113return delegate.getOutputStream();114}115116@Override117protected int available() throws IOException {118return delegate.available();119}120121@Override122protected void close() throws IOException {123delegate.close();124}125126@Override127protected boolean supportsUrgentData() {128return delegate.supportsUrgentData();129}130131@Override132protected void sendUrgentData(int data) throws IOException {133delegate.sendUrgentData(data);134}135136@Override137protected Set<SocketOption<?>> supportedOptions() {138return delegate.supportedOptions();139}140141@Override142protected <T> void setOption(SocketOption<T> opt, T value) throws IOException {143delegate.setOption(opt, value);144}145146@Override147protected <T> T getOption(SocketOption<T> opt) throws IOException {148return delegate.getOption(opt);149}150151@Override152public void setOption(int optID, Object value) throws SocketException {153delegate.setOption(optID, value);154}155156@Override157public Object getOption(int optID) throws SocketException {158return delegate.getOption(optID);159}160161@Override162protected void shutdownInput() throws IOException {163delegate.shutdownInput();164}165166@Override167protected void shutdownOutput() throws IOException {168delegate.shutdownOutput();169}170}171172173