1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package twcsckernel.projectbase.rmi.socketfactory;
16
17 /***
18 * Stores information about socket endpoint (address/port pair).
19 *
20 * @author Tim Taylor -- tttaylor@cssassociates.com
21 */
22 public class EndpointInfo {
23 private String host;
24 private int port;
25
26 /***
27 * Constructor.
28 */
29 public EndpointInfo(String host, int port) {
30 this.host = host;
31 this.port = port;
32 }
33
34 /***
35 * Utility method for creating an endpoint string of the form
36 * address:port.
37 *
38 * @param address The address part of the endpoint string.
39 * @param port The port part of the endpoint string.
40 * @return The endpoint string.
41 */
42 public static String getEndpointString(String address, int port) {
43 return address + ":" + port;
44 }
45
46 /***
47 * Utility method for creating an endpoint string of the form
48 * address:port.
49 *
50 * @param address The address part of the endpoint string.
51 * @param port The port part of the endpoint string.
52 * @return The endpoint string.
53 */
54 public static String getEndpointString(byte[] address, int port) {
55 return getEndpointString(getAddressString(address), port);
56 }
57
58 /***
59 * Utility method to convert an IP address to a string.
60 *
61 * @param address The four bytes of an IP address.
62 * @return The corresponding string (a.b.c.d format).
63 */
64 public static String getAddressString(byte[] address) {
65 return ((int) address[0] &0xff) + "." +
66 ((int) address[1] & 0xff) + "." +
67 ((int) address[2] & 0xff) + "." +
68 ((int) address[3] & 0xff);
69 }
70
71 /*** @return host of this endpoint. */
72 public String getHost() {
73 return host;
74 }
75
76 /*** @return port of this endpoint. */
77 public int getPort() {
78 return port;
79 }
80 }
81