View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *   http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  
18  package org.apache.commons.net.ftp;
19  
20  import java.io.IOException;
21  import java.io.InputStream;
22  import java.io.OutputStream;
23  import java.net.InetAddress;
24  import java.net.Socket;
25  import java.net.SocketAddress;
26  import java.net.SocketException;
27  import java.nio.channels.SocketChannel;
28  import java.util.Objects;
29  import java.util.zip.DeflaterOutputStream;
30  import java.util.zip.InflaterInputStream;
31  
32  /**
33   * Wrapper class for FTP data channel sockets.
34   */
35  abstract class DelegateSocket extends Socket {
36  
37      protected final Socket delegate;
38  
39      DelegateSocket(final Socket delegate) {
40          this.delegate = Objects.requireNonNull(delegate, "delegate");
41      }
42  
43      @Override
44      public void bind(final SocketAddress bindpoint) throws IOException {
45          delegate.bind(bindpoint);
46      }
47  
48      @Override
49      public synchronized void close() throws IOException {
50          delegate.close();
51      }
52  
53      @Override
54      public void connect(final SocketAddress endpoint) throws IOException {
55          delegate.connect(endpoint);
56      }
57  
58      @Override
59      public void connect(final SocketAddress endpoint, final int timeout) throws IOException {
60          delegate.connect(endpoint, timeout);
61      }
62  
63      @Override
64      public SocketChannel getChannel() {
65          return delegate.getChannel();
66      }
67  
68      @Override
69      public InetAddress getInetAddress() {
70          return delegate.getInetAddress();
71      }
72  
73      @Override
74      public InputStream getInputStream() throws IOException {
75          return new InflaterInputStream(delegate.getInputStream());
76      }
77  
78      @Override
79      public boolean getKeepAlive() throws SocketException {
80          return delegate.getKeepAlive();
81      }
82  
83      @Override
84      public InetAddress getLocalAddress() {
85          return delegate.getLocalAddress();
86      }
87  
88      @Override
89      public int getLocalPort() {
90          return delegate.getLocalPort();
91      }
92  
93      @Override
94      public SocketAddress getLocalSocketAddress() {
95          return delegate.getLocalSocketAddress();
96      }
97  
98      @Override
99      public boolean getOOBInline() throws SocketException {
100         return delegate.getOOBInline();
101     }
102 
103     @Override
104     public OutputStream getOutputStream() throws IOException {
105         return new DeflaterOutputStream(delegate.getOutputStream());
106     }
107 
108     @Override
109     public int getPort() {
110         return delegate.getPort();
111     }
112 
113     @Override
114     public synchronized int getReceiveBufferSize() throws SocketException {
115         return delegate.getReceiveBufferSize();
116     }
117 
118     @Override
119     public SocketAddress getRemoteSocketAddress() {
120         return delegate.getRemoteSocketAddress();
121     }
122 
123     @Override
124     public boolean getReuseAddress() throws SocketException {
125         return delegate.getReuseAddress();
126     }
127 
128     @Override
129     public synchronized int getSendBufferSize() throws SocketException {
130         return delegate.getSendBufferSize();
131     }
132 
133     @Override
134     public int getSoLinger() throws SocketException {
135         return delegate.getSoLinger();
136     }
137 
138     @Override
139     public synchronized int getSoTimeout() throws SocketException {
140         return delegate.getSoTimeout();
141     }
142 
143     @Override
144     public boolean getTcpNoDelay() throws SocketException {
145         return delegate.getTcpNoDelay();
146     }
147 
148     @Override
149     public int getTrafficClass() throws SocketException {
150         return delegate.getTrafficClass();
151     }
152 
153     @Override
154     public boolean isBound() {
155         return delegate.isBound();
156     }
157 
158     @Override
159     public boolean isClosed() {
160         return delegate.isClosed();
161     }
162 
163     @Override
164     public boolean isConnected() {
165         return delegate.isConnected();
166     }
167 
168     @Override
169     public boolean isInputShutdown() {
170         return delegate.isInputShutdown();
171     }
172 
173     @Override
174     public boolean isOutputShutdown() {
175         return delegate.isOutputShutdown();
176     }
177 
178     @Override
179     public void sendUrgentData(final int data) throws IOException {
180         delegate.sendUrgentData(data);
181     }
182 
183     @Override
184     public void setKeepAlive(final boolean on) throws SocketException {
185         delegate.setKeepAlive(on);
186     }
187 
188     @Override
189     public void setOOBInline(final boolean on) throws SocketException {
190         delegate.setOOBInline(on);
191     }
192 
193     @Override
194     public void setPerformancePreferences(final int connectionTime, final int latency, final int bandwidth) {
195         delegate.setPerformancePreferences(connectionTime, latency, bandwidth);
196     }
197 
198     @Override
199     public synchronized void setReceiveBufferSize(final int size) throws SocketException {
200         delegate.setReceiveBufferSize(size);
201     }
202 
203     @Override
204     public void setReuseAddress(final boolean on) throws SocketException {
205         delegate.setReuseAddress(on);
206     }
207 
208     @Override
209     public synchronized void setSendBufferSize(final int size) throws SocketException {
210         delegate.setSendBufferSize(size);
211     }
212 
213     @Override
214     public void setSoLinger(final boolean on, final int linger) throws SocketException {
215         delegate.setSoLinger(on, linger);
216     }
217 
218     @Override
219     public synchronized void setSoTimeout(final int timeout) throws SocketException {
220         delegate.setSoTimeout(timeout);
221     }
222 
223     @Override
224     public void setTcpNoDelay(final boolean on) throws SocketException {
225         delegate.setTcpNoDelay(on);
226     }
227 
228     @Override
229     public void setTrafficClass(final int tc) throws SocketException {
230         delegate.setTrafficClass(tc);
231     }
232 
233     @Override
234     public void shutdownInput() throws IOException {
235         delegate.shutdownInput();
236     }
237 
238     @Override
239     public void shutdownOutput() throws IOException {
240         delegate.shutdownOutput();
241     }
242 
243     @Override
244     public String toString() {
245         return delegate.toString();
246     }
247 }