List of usage examples for java.net UnknownHostException printStackTrace
public void printStackTrace()
From source file:Main.java
public static Map<String, Object> getDomainIp(String _dormain) { Map<String, Object> map = new HashMap<String, Object>(); long start = 0; long end = 0; String time = null;/*from ww w .ja v a 2s .co m*/ InetAddress[] remoteInet = null; try { start = System.currentTimeMillis(); remoteInet = InetAddress.getAllByName(_dormain); if (remoteInet != null) { end = System.currentTimeMillis(); time = (end - start) + ""; } } catch (UnknownHostException e) { end = System.currentTimeMillis(); time = (end - start) + ""; remoteInet = null; e.printStackTrace(); } finally { map.put("remoteInet", remoteInet); map.put("useTime", time); } return map; }
From source file:com.savoycraft.util.TimeUtil.java
/** * Queries a NIST time server to get a difference between its time and the * local system time.// ww w . j a va 2 s. co m */ public static void calibrate() { if (System.currentTimeMillis() < lastTimeRequest + 5000 || calibrated) { return; } NTPUDPClient timeClient = new NTPUDPClient(); InetAddress inetAddress = null; try { inetAddress = InetAddress.getByName(TIME_SERVER); } catch (UnknownHostException e) { // TODO Auto-generated catch block e.printStackTrace(); return; } TimeInfo timeInfo = null; try { timeInfo = timeClient.getTime(inetAddress); } catch (IOException e) { System.err.println("SavoyCraft could not contact time.nist.gov."); e.printStackTrace(); return; } long returnTime = timeInfo.getReturnTime(); calibration = System.currentTimeMillis() - returnTime; System.out.println(calibration); // Date time = new Date(returnTime); // System.out.println("Time from " + TIME_SERVER + ": " + time); lastTimeRequest = System.currentTimeMillis(); calibrated = true; }
From source file:com.singular.utils.FileUtils.java
public static String getCurrentHost() { String hostname = "localhost"; try {/*www . ja va 2 s . c o m*/ hostname = InetAddress.getLocalHost().getHostName(); } catch (UnknownHostException e) { e.printStackTrace(); } return hostname; }
From source file:com.vinexs.tool.NetworkManager.java
public static String getLocalIPAddress() { try {//w w w . j av a2s. c o m InetAddress meHost = InetAddress.getLocalHost(); return meHost.getHostAddress(); } catch (UnknownHostException e) { e.printStackTrace(); return "127.0.0.1"; } }
From source file:net.unicon.academus.apps.download.DownloadServiceFileSystem.java
/** * Generate a unique host identifier using the host's IP address. * @return unique host identifier/*from w ww . j a v a2 s . co m*/ */ private static long generateHostIdentifier() { long hostId; InetAddress lhost = null; try { lhost = InetAddress.getLocalHost(); byte[] addr = lhost.getAddress(); hostId = ((addr[0] & 0xff) << 24) + ((addr[1] & 0xff) << 16) + ((addr[2] & 0xff) << 8) + (addr[3] & 0xff); } catch (UnknownHostException e) { e.printStackTrace(); hostId = -1; } if (log.isDebugEnabled()) { log.debug("System host identifier: " + hostId); } return hostId; }
From source file:hd3gtv.mydmam.db.orm.AutotestOrm.java
public static AutotestOrm populate(int index) { AutotestOrm result = new AutotestOrm(); result.key = "THISISMYKEY" + String.valueOf(index); result.strvalue = "Hello world with cnts"; result.bytvalue = result.strvalue.toUpperCase().getBytes(); result.intvalue = 42;/*w w w.j a v a 2s.c om*/ result.lngvalue = -3329447494103907027L; result.bolvalue = true; result.fltvalue = 6.55957f; result.dlbvalue = (double) result.lngvalue / 11d; result.uuivalue = UUID.fromString("110E8400-E29B-11D4-A716-446655440000"); result.jsovalue = new JSONObject(); result.jsovalue.put("Hello", "world"); result.jsovalue.put("Count", index); result.jsavalue = new JSONArray(); result.jsavalue.add("One"); result.jsavalue.add(42); result.jsavalue.add("Un"); try { result.addressvalue = InetAddress.getLocalHost(); } catch (UnknownHostException e) { e.printStackTrace(); } result.sbuvalue = new StringBuffer(); result.sbuvalue.append(result.key); result.sbuvalue.append(result.strvalue); result.sbuvalue.append(result.lngvalue); result.calendarvalue = Calendar.getInstance(); result.calendarvalue.set(1995, 05, 23, 10, 04, 8); result.calendarvalue.set(Calendar.MILLISECOND, 666); result.dtevalue = result.calendarvalue.getTime(); result.strarrayvalue = new String[2]; result.strarrayvalue[0] = result.strvalue; result.strarrayvalue[1] = result.key; result.serializvalue = new HashMap<String, String>(); result.serializvalue.put("Some var", result.strvalue); result.serializvalue.put("Other var", result.uuivalue.toString()); result.enumvalue = MyEnum.ME; result.iamempty = ""; result.iamanindex = index; result.donttouchme = "F*ck you"; return result; }
From source file:edu.umass.cs.nio.nioutils.SampleNodeConfig.java
/** * @return Local host address.//from w w w. j ava 2 s. co m */ public static InetAddress getLocalAddress() { InetAddress localAddr = null; try { localAddr = InetAddress.getByName("localhost"); } catch (UnknownHostException e) { e.printStackTrace(); } return localAddr; }
From source file:org.schabi.newpipe.Downloader.java
/**Common functionality between download(String url) and download(String url, String language)*/ private static String dl(HttpsURLConnection con) throws IOException { StringBuilder response = new StringBuilder(); try {//from ww w . j a v a2 s . c om con.setRequestMethod("GET"); con.setRequestProperty("User-Agent", USER_AGENT); BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream())); String inputLine; while ((inputLine = in.readLine()) != null) { response.append(inputLine); } in.close(); } catch (UnknownHostException uhe) {//thrown when there's no internet connection uhe.printStackTrace(); //Toast.makeText(getActivity(), uhe.getMessage(), Toast.LENGTH_LONG).show(); } return response.toString(); }
From source file:com.anyi.gp.license.RegisterTools.java
public static String getHostName() { try {/*from w w w.java2 s . c o m*/ return InetAddress.getLocalHost().getHostName(); } catch (UnknownHostException e) { e.printStackTrace(); } return ""; }
From source file:org.apache.geode.internal.cache.ClusterConfigurationLoader.java
/** * Request the shared configuration for group(s) from locator(s) this member is bootstrapped with. * * This will request the group config this server belongs plus the "cluster" config * /* w w w.j a v a2 s. c om*/ * @param config this member's configuration. * @return {@link ConfigurationResponse} */ public static ConfigurationResponse requestConfigurationFromLocators(DistributionConfig config, List<String> locatorList) throws ClusterConfigurationNotAvailableException, UnknownHostException { List<String> groups = ClusterConfigurationLoader.getGroups(config); ConfigurationRequest request = new ConfigurationRequest(); request.addGroups(ClusterConfigurationService.CLUSTER_CONFIG); for (String group : groups) { request.addGroups(group); } request.setNumAttempts(10); ConfigurationResponse response = null; // Try talking to all the locators in the list // to get the shared configuration. TcpClient client = new TcpClient(); for (String locatorInfo : locatorList) { DistributionLocatorId dlId = new DistributionLocatorId(locatorInfo); String ipaddress = dlId.getBindAddress(); InetAddress locatorInetAddress = null; if (StringUtils.isNotBlank(ipaddress)) { locatorInetAddress = InetAddress.getByName(ipaddress); } else { locatorInetAddress = dlId.getHost().getAddress(); } int port = dlId.getPort(); try { response = (ConfigurationResponse) client.requestToServer(locatorInetAddress, port, request, 10000); } catch (UnknownHostException e) { e.printStackTrace(); } catch (IOException e) { // TODO Log e.printStackTrace(); } catch (ClassNotFoundException e) { e.printStackTrace(); } } // if the response is null , that means Shared Configuration service is not installed on the // locator // and hence it returns null if (response == null || response.failedToGetSharedConfig()) { throw new ClusterConfigurationNotAvailableException( LocalizedStrings.Launcher_Command_FAILED_TO_GET_SHARED_CONFIGURATION.toLocalizedString()); } return response; }