DelegateSocket.java

  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. package org.apache.commons.net.ftp;

  18. import java.io.IOException;
  19. import java.io.InputStream;
  20. import java.io.OutputStream;
  21. import java.net.InetAddress;
  22. import java.net.Socket;
  23. import java.net.SocketAddress;
  24. import java.net.SocketException;
  25. import java.nio.channels.SocketChannel;
  26. import java.util.Objects;
  27. import java.util.zip.DeflaterOutputStream;
  28. import java.util.zip.InflaterInputStream;

  29. /**
  30.  * Wrapper class for FTP data channel sockets.
  31.  */
  32. abstract class DelegateSocket extends Socket {

  33.     protected final Socket delegate;

  34.     DelegateSocket(final Socket delegate) {
  35.         this.delegate = Objects.requireNonNull(delegate, "delegate");
  36.     }

  37.     @Override
  38.     public void bind(final SocketAddress bindpoint) throws IOException {
  39.         delegate.bind(bindpoint);
  40.     }

  41.     @Override
  42.     public synchronized void close() throws IOException {
  43.         delegate.close();
  44.     }

  45.     @Override
  46.     public void connect(final SocketAddress endpoint) throws IOException {
  47.         delegate.connect(endpoint);
  48.     }

  49.     @Override
  50.     public void connect(final SocketAddress endpoint, final int timeout) throws IOException {
  51.         delegate.connect(endpoint, timeout);
  52.     }

  53.     @Override
  54.     public SocketChannel getChannel() {
  55.         return delegate.getChannel();
  56.     }

  57.     @Override
  58.     public InetAddress getInetAddress() {
  59.         return delegate.getInetAddress();
  60.     }

  61.     @Override
  62.     public InputStream getInputStream() throws IOException {
  63.         return new InflaterInputStream(delegate.getInputStream());
  64.     }

  65.     @Override
  66.     public boolean getKeepAlive() throws SocketException {
  67.         return delegate.getKeepAlive();
  68.     }

  69.     @Override
  70.     public InetAddress getLocalAddress() {
  71.         return delegate.getLocalAddress();
  72.     }

  73.     @Override
  74.     public int getLocalPort() {
  75.         return delegate.getLocalPort();
  76.     }

  77.     @Override
  78.     public SocketAddress getLocalSocketAddress() {
  79.         return delegate.getLocalSocketAddress();
  80.     }

  81.     @Override
  82.     public boolean getOOBInline() throws SocketException {
  83.         return delegate.getOOBInline();
  84.     }

  85.     @Override
  86.     public OutputStream getOutputStream() throws IOException {
  87.         return new DeflaterOutputStream(delegate.getOutputStream());
  88.     }

  89.     @Override
  90.     public int getPort() {
  91.         return delegate.getPort();
  92.     }

  93.     @Override
  94.     public synchronized int getReceiveBufferSize() throws SocketException {
  95.         return delegate.getReceiveBufferSize();
  96.     }

  97.     @Override
  98.     public SocketAddress getRemoteSocketAddress() {
  99.         return delegate.getRemoteSocketAddress();
  100.     }

  101.     @Override
  102.     public boolean getReuseAddress() throws SocketException {
  103.         return delegate.getReuseAddress();
  104.     }

  105.     @Override
  106.     public synchronized int getSendBufferSize() throws SocketException {
  107.         return delegate.getSendBufferSize();
  108.     }

  109.     @Override
  110.     public int getSoLinger() throws SocketException {
  111.         return delegate.getSoLinger();
  112.     }

  113.     @Override
  114.     public synchronized int getSoTimeout() throws SocketException {
  115.         return delegate.getSoTimeout();
  116.     }

  117.     @Override
  118.     public boolean getTcpNoDelay() throws SocketException {
  119.         return delegate.getTcpNoDelay();
  120.     }

  121.     @Override
  122.     public int getTrafficClass() throws SocketException {
  123.         return delegate.getTrafficClass();
  124.     }

  125.     @Override
  126.     public boolean isBound() {
  127.         return delegate.isBound();
  128.     }

  129.     @Override
  130.     public boolean isClosed() {
  131.         return delegate.isClosed();
  132.     }

  133.     @Override
  134.     public boolean isConnected() {
  135.         return delegate.isConnected();
  136.     }

  137.     @Override
  138.     public boolean isInputShutdown() {
  139.         return delegate.isInputShutdown();
  140.     }

  141.     @Override
  142.     public boolean isOutputShutdown() {
  143.         return delegate.isOutputShutdown();
  144.     }

  145.     @Override
  146.     public void sendUrgentData(final int data) throws IOException {
  147.         delegate.sendUrgentData(data);
  148.     }

  149.     @Override
  150.     public void setKeepAlive(final boolean on) throws SocketException {
  151.         delegate.setKeepAlive(on);
  152.     }

  153.     @Override
  154.     public void setOOBInline(final boolean on) throws SocketException {
  155.         delegate.setOOBInline(on);
  156.     }

  157.     @Override
  158.     public void setPerformancePreferences(final int connectionTime, final int latency, final int bandwidth) {
  159.         delegate.setPerformancePreferences(connectionTime, latency, bandwidth);
  160.     }

  161.     @Override
  162.     public synchronized void setReceiveBufferSize(final int size) throws SocketException {
  163.         delegate.setReceiveBufferSize(size);
  164.     }

  165.     @Override
  166.     public void setReuseAddress(final boolean on) throws SocketException {
  167.         delegate.setReuseAddress(on);
  168.     }

  169.     @Override
  170.     public synchronized void setSendBufferSize(final int size) throws SocketException {
  171.         delegate.setSendBufferSize(size);
  172.     }

  173.     @Override
  174.     public void setSoLinger(final boolean on, final int linger) throws SocketException {
  175.         delegate.setSoLinger(on, linger);
  176.     }

  177.     @Override
  178.     public synchronized void setSoTimeout(final int timeout) throws SocketException {
  179.         delegate.setSoTimeout(timeout);
  180.     }

  181.     @Override
  182.     public void setTcpNoDelay(final boolean on) throws SocketException {
  183.         delegate.setTcpNoDelay(on);
  184.     }

  185.     @Override
  186.     public void setTrafficClass(final int tc) throws SocketException {
  187.         delegate.setTrafficClass(tc);
  188.     }

  189.     @Override
  190.     public void shutdownInput() throws IOException {
  191.         delegate.shutdownInput();
  192.     }

  193.     @Override
  194.     public void shutdownOutput() throws IOException {
  195.         delegate.shutdownOutput();
  196.     }

  197.     @Override
  198.     public String toString() {
  199.         return delegate.toString();
  200.     }
  201. }