1 /* GENERATED SOURCE. DO NOT MODIFY. */ 2 /* 3 * Copyright (C) 2015 The Android Open Source Project 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * 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 tests.net; 18 import java.io.IOException; 19 import java.net.InetAddress; 20 import java.net.Socket; 21 import java.net.UnknownHostException; 22 import javax.net.SocketFactory; 23 /** 24 * {@link SocketFactory} which delegates all invocations to the provided delegate 25 * {@code SocketFactory}. 26 * @hide This class is not part of the Android public SDK API 27 */ 28 public class DelegatingSocketFactory extends SocketFactory { 29 private final SocketFactory mDelegate; 30 public DelegatingSocketFactory(SocketFactory delegate) { 31 this.mDelegate = delegate; 32 } 33 /** 34 * Invoked after obtaining a socket from the delegate and before returning it to the caller. 35 * 36 * <p>The default implementation does nothing. 37 */ 38 protected Socket configureSocket(Socket socket) throws IOException { 39 return socket; 40 } 41 @Override 42 public Socket createSocket() throws IOException { 43 Socket socket = mDelegate.createSocket(); 44 return configureSocket(socket); 45 } 46 @Override 47 public Socket createSocket(String host, int port) throws IOException, UnknownHostException { 48 Socket socket = mDelegate.createSocket(host, port); 49 return configureSocket(socket); 50 } 51 @Override 52 public Socket createSocket(String host, int port, InetAddress localHost, int localPort) 53 throws IOException, UnknownHostException { 54 Socket socket = mDelegate.createSocket(host, port, localHost, localPort); 55 return configureSocket(socket); 56 } 57 @Override 58 public Socket createSocket(InetAddress host, int port) throws IOException { 59 Socket socket = mDelegate.createSocket(host, port); 60 return configureSocket(socket); 61 } 62 @Override 63 public Socket createSocket(InetAddress address, int port, InetAddress localAddress, 64 int localPort) throws IOException { 65 Socket socket = mDelegate.createSocket(address, port, localAddress, localPort); 66 return configureSocket(socket); 67 } 68 } 69