1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32 package org.apache.commons.httpclient.protocol;
33
34 import java.io.IOException;
35 import java.net.InetAddress;
36 import java.net.Socket;
37 import java.net.UnknownHostException;
38
39 /***
40 * The default class for creating protocol sockets. This class just uses the
41 * {@link java.net.Socket socket} constructors.
42 *
43 * @author Michael Becke
44 *
45 * @since 2.0
46 */
47 public class DefaultProtocolSocketFactory implements ProtocolSocketFactory {
48
49 /***
50 * The factory singleton.
51 */
52 private static final DefaultProtocolSocketFactory factory = new DefaultProtocolSocketFactory();
53
54 /***
55 * Gets an singleton instance of the DefaultProtocolSocketFactory.
56 * @return a DefaultProtocolSocketFactory
57 */
58 static DefaultProtocolSocketFactory getSocketFactory() {
59 return factory;
60 }
61
62 /***
63 * Constructor for DefaultProtocolSocketFactory.
64 */
65 public DefaultProtocolSocketFactory() {
66 super();
67 }
68
69 /***
70 * @see #createSocket(java.lang.String,int,java.net.InetAddress,int)
71 */
72 public Socket createSocket(
73 String host,
74 int port,
75 InetAddress clientHost,
76 int clientPort
77 ) throws IOException, UnknownHostException {
78 return new Socket(host, port, clientHost, clientPort);
79 }
80
81 /***
82 * @see ProtocolSocketFactory#createSocket(java.lang.String,int)
83 */
84 public Socket createSocket(String host, int port)
85 throws IOException, UnknownHostException {
86 return new Socket(host, port);
87 }
88
89 /***
90 * All instances of DefaultProtocolSocketFactory are the same.
91 */
92 public boolean equals(Object obj) {
93 return ((obj != null) && obj.getClass().equals(DefaultProtocolSocketFactory.class));
94 }
95
96 /***
97 * All instances of DefaultProtocolSocketFactory have the same hash code.
98 */
99 public int hashCode() {
100 return DefaultProtocolSocketFactory.class.hashCode();
101 }
102
103 }