source: trunk/autoquest-plugin-http/src/main/java/de/ugoe/cs/autoquest/plugin/http/HTTPUtils.java @ 1367

Last change on this file since 1367 was 1367, checked in by pharms, 10 years ago

Initial import.

File size: 2.0 KB
Line 
1//   Copyright 2012 Georg-August-Universität Göttingen, Germany
2//
3//   Licensed under the Apache License, Version 2.0 (the "License");
4//   you may not use this file except in compliance with the License.
5//   You may obtain a copy of the License at
6//
7//       http://www.apache.org/licenses/LICENSE-2.0
8//
9//   Unless required by applicable law or agreed to in writing, software
10//   distributed under the License is distributed on an "AS IS" BASIS,
11//   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12//   See the License for the specific language governing permissions and
13//   limitations under the License.
14
15package de.ugoe.cs.autoquest.plugin.http;
16
17import de.ugoe.cs.autoquest.httpmonitor.exchange.Address;
18
19/**
20 * <p>
21 * TODO comment
22 * </p>
23 *
24 * @author Patrick Harms
25 */
26public class HTTPUtils {
27
28    /**
29     * <p>
30     * converts an address to a simple string containing either host or ip and the port number
31     * if any.
32     * </p>
33     *
34     * @param address the address to convert
35     *
36     * @return either "host:port" or "ip:port" or "host" or "ip" or "port" or null
37     */
38    public static String toString(Address address) {
39        if (address != null) {
40            StringBuffer buffer = new StringBuffer();
41            String prefix = "";
42            if (address.getHost() != null) {
43                buffer.append(address.getHost());
44                prefix = ":";
45            }
46            else if (address.getIp() != null) {
47                buffer.append(prefix);
48                buffer.append(address.getIp());
49                prefix = ":";
50            }
51
52            if (address.getPort() != null) {
53                buffer.append(prefix);
54                buffer.append(address.getPort());
55            }
56
57            if (buffer.length() > 0) {
58                return buffer.toString();
59            }
60        }
61
62        return null;
63    }
64   
65    /**
66     * <p>
67     * prevent instantiation
68     * </p>
69     */
70    private HTTPUtils() { }
71   
72}
Note: See TracBrowser for help on using the repository browser.