Debian Codegraph @

src/main/org/h2/util/NetworkConnectionInfo.java

raw
1 /*
2 * Copyright 2004-2023 H2 Group. Multiple-Licensed under the MPL 2.0,
3 * and the EPL 1.0 (https://h2database.com/html/license.html).
4 * Initial Developer: H2 Group
5 */
6 package org.h2.util;
7
8 import java.net.InetAddress;
9 import java.net.UnknownHostException;
10
11 /**
12 * Network connection information.
13 */
14 public final class NetworkConnectionInfo {
15
16 private final String server;
17
18 private final byte[] clientAddr;
19
20 private final int clientPort;
21
22 private final String clientInfo;
23
24 /**
25 * Creates new instance of network connection information.
26 *
27 * @param server
28 * the protocol and port of the server
29 * @param clientAddr
30 * the client address
31 * @param clientPort
32 * the client port
33 * @throws UnknownHostException
34 * if clientAddr cannot be resolved
35 */
36 public NetworkConnectionInfo(String server, String clientAddr, int clientPort) throws UnknownHostException {
37 this(server, InetAddress.getByName(clientAddr).getAddress(), clientPort, null);
38 }
39
40 /**
41 * Creates new instance of network connection information.
42 *
43 * @param server
44 * the protocol and port of the server
45 * @param clientAddr
46 * the client address
47 * @param clientPort
48 * the client port
49 * @param clientInfo
50 * additional client information, or {@code null}
51 */
52 public NetworkConnectionInfo(String server, byte[] clientAddr, int clientPort, String clientInfo) {
53 this.server = server;
54 this.clientAddr = clientAddr;
55 this.clientPort = clientPort;
56 this.clientInfo = clientInfo;
57 }
58
59 /**
60 * Returns the protocol and port of the server.
61 *
62 * @return the protocol and port of the server
63 */
64 public String getServer() {
65 return server;
66 }
67
68 /**
69 * Returns the client address.
70 *
71 * @return the client address
72 */
73 public byte[] getClientAddr() {
74 return clientAddr;
75 }
76
77 /**
78 * Returns the client port.
79 *
80 * @return the client port
81 */
82 public int getClientPort() {
83 return clientPort;
84 }
85
86 /**
87 * Returns additional client information, or {@code null}.
88 *
89 * @return additional client information, or {@code null}
90 */
91 public String getClientInfo() {
92 return clientInfo;
93 }
94
95 /**
96 * Returns the client address and port.
97 *
98 * @return the client address and port
99 */
100 public String getClient() {
101 return NetUtils.ipToShortForm(new StringBuilder(), clientAddr, true).append(':').append(clientPort).toString();
102 }
103
104 }