55102
|
1 |
/*
|
|
2 |
* Copyright (c) 2019, 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.
|
|
8 |
*
|
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
13 |
* accompanied this code).
|
|
14 |
*
|
|
15 |
* You should have received a copy of the GNU General Public License version
|
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
18 |
*
|
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
20 |
* or visit www.oracle.com if you need additional information or have any
|
|
21 |
* questions.
|
|
22 |
*/
|
|
23 |
|
|
24 |
package java.net;
|
|
25 |
|
|
26 |
import java.io.InputStream;
|
|
27 |
import java.io.OutputStream;
|
|
28 |
import java.io.IOException;
|
|
29 |
import java.util.Set;
|
|
30 |
|
|
31 |
/**
|
|
32 |
* A SocketImpl that delegates all operations to a platform SocketImpl. It also
|
|
33 |
* overrides all methods with public methods and implements AutoCloseable to make
|
|
34 |
* it easy to write tests.
|
|
35 |
*/
|
|
36 |
|
|
37 |
public class PlatformSocketImpl extends SocketImpl implements AutoCloseable {
|
|
38 |
private final SocketImpl impl;
|
|
39 |
|
|
40 |
public PlatformSocketImpl(boolean server) {
|
|
41 |
impl = new sun.nio.ch.NioSocketImpl(server);
|
|
42 |
}
|
|
43 |
|
|
44 |
@Override
|
|
45 |
public void close() throws IOException {
|
|
46 |
impl.close();
|
|
47 |
}
|
|
48 |
|
|
49 |
@Override
|
|
50 |
public void create(boolean stream) throws IOException {
|
|
51 |
impl.create(stream);
|
|
52 |
}
|
|
53 |
|
|
54 |
@Override
|
|
55 |
public void connect(SocketAddress remote, int millis) throws IOException {
|
|
56 |
impl.connect(remote, millis);
|
|
57 |
}
|
|
58 |
|
|
59 |
@Override
|
|
60 |
public void connect(String host, int port) throws IOException {
|
|
61 |
impl.connect(host, port);
|
|
62 |
}
|
|
63 |
|
|
64 |
@Override
|
|
65 |
public void connect(InetAddress address, int port) throws IOException {
|
|
66 |
impl.connect(address, port);
|
|
67 |
}
|
|
68 |
|
|
69 |
@Override
|
|
70 |
public void bind(InetAddress address, int port) throws IOException {
|
|
71 |
impl.bind(address, port);
|
|
72 |
}
|
|
73 |
|
|
74 |
@Override
|
|
75 |
public void listen(int backlog) throws IOException {
|
|
76 |
impl.listen(backlog);
|
|
77 |
}
|
|
78 |
|
|
79 |
@Override
|
|
80 |
public void accept(SocketImpl si) throws IOException {
|
|
81 |
impl.accept(((PlatformSocketImpl) si).impl);
|
|
82 |
}
|
|
83 |
|
|
84 |
@Override
|
|
85 |
public InputStream getInputStream() throws IOException {
|
|
86 |
return impl.getInputStream();
|
|
87 |
}
|
|
88 |
|
|
89 |
@Override
|
|
90 |
public OutputStream getOutputStream() throws IOException {
|
|
91 |
return impl.getOutputStream();
|
|
92 |
}
|
|
93 |
|
|
94 |
@Override
|
|
95 |
public int available() throws IOException {
|
|
96 |
return impl.available();
|
|
97 |
}
|
|
98 |
|
|
99 |
@Override
|
|
100 |
public Set<SocketOption<?>> supportedOptions() {
|
|
101 |
return impl.supportedOptions();
|
|
102 |
}
|
|
103 |
|
|
104 |
@Override
|
|
105 |
public <T> void setOption(SocketOption<T> opt, T value) throws IOException {
|
|
106 |
impl.setOption(opt, value);
|
|
107 |
}
|
|
108 |
|
|
109 |
@Override
|
|
110 |
public <T> T getOption(SocketOption<T> opt) throws IOException {
|
|
111 |
return impl.getOption(opt);
|
|
112 |
}
|
|
113 |
|
|
114 |
@Override
|
|
115 |
public void setOption(int opt, Object value) throws SocketException {
|
|
116 |
impl.setOption(opt, value);
|
|
117 |
}
|
|
118 |
|
|
119 |
@Override
|
|
120 |
public Object getOption(int opt) throws SocketException {
|
|
121 |
return impl.getOption(opt);
|
|
122 |
}
|
|
123 |
|
|
124 |
@Override
|
|
125 |
public void shutdownInput() throws IOException {
|
|
126 |
impl.shutdownInput();
|
|
127 |
}
|
|
128 |
|
|
129 |
@Override
|
|
130 |
public void shutdownOutput() throws IOException {
|
|
131 |
impl.shutdownOutput();
|
|
132 |
}
|
|
133 |
|
|
134 |
@Override
|
|
135 |
public boolean supportsUrgentData() {
|
|
136 |
return impl.supportsUrgentData();
|
|
137 |
}
|
|
138 |
|
|
139 |
@Override
|
|
140 |
public void sendUrgentData(int data) throws IOException {
|
|
141 |
impl.sendUrgentData(data);
|
|
142 |
}
|
|
143 |
}
|