1 19 20 package com.sslexplorer.boot; 21 22 import java.net.InetAddress ; 23 import java.net.UnknownHostException ; 24 25 34 public class HostService { 35 36 38 private String hostname; 39 private int port; 40 41 42 48 public HostService(String hostname, int port) { 49 super(); 50 this.hostname = hostname; 51 this.port = port; 52 } 53 54 59 public HostService(String uri) { 60 int i = uri.indexOf(':'); 61 if (i != -1) { 62 String addr = uri.substring(0, i); 63 if (addr.indexOf('/') > 0) 64 addr = addr.substring(addr.indexOf('/') + 1); 65 uri = uri.substring(i + 1); 66 if (addr.length() > 0) { 67 hostname = addr; 68 } 69 } 70 71 try { 72 port = Integer.parseInt(uri); 73 } 74 catch(NumberFormatException nfe) { 75 hostname = uri; 76 } 77 } 78 79 84 public String getHost() { 85 return hostname; 86 } 87 88 93 public void setHost(String hostname) { 94 this.hostname = hostname; 95 } 96 97 102 public int getPort() { 103 return port; 104 } 105 106 111 public void setPort(int port) { 112 this.port = port; 113 } 114 115 121 public InetAddress getAddress() throws UnknownHostException { 122 return InetAddress.getByName(getHost()); 123 } 124 125 130 public String toString() { 131 return getHost() + ":" + getPort(); 132 } 133 } 134 | Popular Tags |