List of usage examples for java.net SocketException toString
public String toString()
From source file:com.sckftr.android.utils.net.Network.java
/** * Get IP address from first non-localhost interface * @return address or empty string// w ww . j a va 2 s . com */ public static String getLocalIpAddress() { try { for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en .hasMoreElements();) { NetworkInterface intf = en.nextElement(); for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) { InetAddress inetAddress = enumIpAddr.nextElement(); if (!inetAddress.isLoopbackAddress()) { String ip = Formatter.formatIpAddress(inetAddress.hashCode()); Log.i("NET", "***** IP=" + ip); return ip; } } } } catch (SocketException ex) { Log.e("NET", ex.toString()); } return null; }
From source file:de.madvertise.android.sdk.MadUtil.java
/** * Fetch the address of the enabled interface * /*from ww w .j ava 2s. c o m*/ * @return ip address as string */ protected static String getLocalIpAddress() { try { for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en .hasMoreElements();) { NetworkInterface intf = en.nextElement(); for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) { InetAddress inetAddress = enumIpAddr.nextElement(); if (!inetAddress.isLoopbackAddress()) { return inetAddress.getHostAddress().toString(); } } } } catch (SocketException ex) { if (PRINT_LOG) Log.d(MadUtil.LOG, ex.toString()); } return ""; }
From source file:com.max2idea.android.fwknop.Fwknop.java
public static String getLocalIpAddress() { try {/* w ww .jav a2s. c o m*/ for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en .hasMoreElements();) { NetworkInterface intf = en.nextElement(); for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) { InetAddress inetAddress = enumIpAddr.nextElement(); if (!inetAddress.isLoopbackAddress()) { Log.v("Internal ip", inetAddress.getHostAddress().toString()); return inetAddress.getHostAddress().toString(); } } } } catch (SocketException ex) { Log.e("Internal IP", ex.toString()); } return null; }
From source file:org.apache.hama.manager.LogView.java
/** * download log file./*from ww w . ja v a 2 s.co m*/ * * @param filPath log file path. * @throws Exception */ public static void downloadFile(HttpServletResponse response, String filePath) throws ServletException, IOException { File file = new File(filePath); if (!file.exists()) { throw new ServletException("File doesn't exists."); } String headerKey = "Content-Disposition"; String headerValue = "attachment; filename=\"" + file.getName() + "\""; BufferedInputStream in = null; BufferedOutputStream out = null; try { response.setContentType("application/octet-stream"); response.setContentLength((int) file.length()); response.setHeader(headerKey, headerValue); in = new BufferedInputStream(new FileInputStream(file)); out = new BufferedOutputStream(response.getOutputStream()); byte[] buffer = new byte[4 * 1024]; int read = -1; while ((read = in.read(buffer)) != -1) { out.write(buffer, 0, read); } } catch (SocketException e) { // download cancel.. } catch (Exception e) { response.reset(); response.sendError(HttpURLConnection.HTTP_INTERNAL_ERROR, e.toString()); } finally { if (in != null) { in.close(); } if (out != null) { out.flush(); out.close(); } } }
From source file:com.sentaroh.android.SMBSync2.CommonUtilities.java
public static String getIfIpAddress() { String result = ""; try {//from w w w . j a va2 s.c om for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en .hasMoreElements();) { NetworkInterface intf = en.nextElement(); for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) { InetAddress inetAddress = enumIpAddr.nextElement(); // Log.v("","ip="+inetAddress.getHostAddress()); if (!inetAddress.isLoopbackAddress() && (inetAddress.getHostAddress().startsWith("0") || inetAddress.getHostAddress().startsWith("1") || inetAddress.getHostAddress().startsWith("2"))) { result = inetAddress.getHostAddress(); break; } } } } catch (SocketException ex) { Log.e(APPLICATION_TAG, ex.toString()); result = "192.168.0.1"; } // Log.v("","getIfIpAddress result="+result); if (result.equals("")) result = "192.168.0.1"; return result; }
From source file:com.sentaroh.android.SMBSync2.CommonUtilities.java
public static String getLocalIpAddress() { String result = ""; boolean exit = false; try {/*from w w w . j av a 2 s . co m*/ for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en .hasMoreElements();) { NetworkInterface intf = en.nextElement(); for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) { InetAddress inetAddress = enumIpAddr.nextElement(); // if (!inetAddress.isLoopbackAddress() && !(inetAddress.toString().indexOf(":")>=0)) { // return inetAddress.getHostAddress().toString(); // } // Log.v("","ip="+inetAddress.getHostAddress()+ // ", name="+intf.getName()); if (inetAddress.isSiteLocalAddress()) { result = inetAddress.getHostAddress(); // Log.v("","result="+result+", name="+intf.getName()+"-"); if (intf.getName().equals("wlan0")) { exit = true; break; } } } if (exit) break; } } catch (SocketException ex) { Log.e(APPLICATION_TAG, ex.toString()); result = "192.168.0.1"; } // Log.v("","getLocalIpAddress result="+result); if (result.equals("")) result = "192.168.0.1"; return result; }
From source file:com.example.zoetablet.BasicFragmentActivity.java
protected static String getLocalIpAddress() { try {/* ww w . j ava 2s . c om*/ for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en .hasMoreElements();) { NetworkInterface intf = en.nextElement(); for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) { InetAddress inetAddress = enumIpAddr.nextElement(); if (!inetAddress.isLoopbackAddress()) { return inetAddress.getHostAddress().toString(); } } } } catch (SocketException ex) { Log.e("Tablet", ex.toString()); } return null; }
From source file:com.googlecode.networklog.NetworkLog.java
public static void getLocalIpAddresses() { MyLog.d("getLocalIpAddresses"); localIpAddrs = new ArrayList<String>(); try {// www . j ava 2s. c o m for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en .hasMoreElements();) { NetworkInterface intf = en.nextElement(); MyLog.d("Network interface found: " + intf.toString()); for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) { InetAddress inetAddress = enumIpAddr.nextElement(); MyLog.d("InetAddress: " + inetAddress.toString()); if (!inetAddress.isLoopbackAddress()) { MyLog.d("Adding local IP address: [" + inetAddress.getHostAddress().toString() + "]"); localIpAddrs.add(inetAddress.getHostAddress().toString()); } } } } catch (SocketException ex) { Log.e("NetworkLog", ex.toString()); } }
From source file:org.darwinathome.server.controller.WebstartController.java
@RequestMapping("/{jarFile}.jar") public void jarFile(@PathVariable String jarFile, HttpServletResponse response) { log.info("Request for " + jarFile); String realFileName = servletContext.getRealPath(jarFile + ".jar"); File realFile = new File(realFileName); response.setContentType("application/java-archive"); response.setContentLength((int) realFile.length()); try {/*ww w.j av a 2s . com*/ InputStream in = new FileInputStream(realFileName); OutputStream out = response.getOutputStream(); try { byte[] buffer = new byte[8192]; int read; while ((read = in.read(buffer)) > 0) { out.write(buffer, 0, read); } } finally { in.close(); } } catch (SocketException e) { log.info("While writing jar: " + e.toString()); } catch (EOFException e) { log.info("Broken pipe while requesting " + jarFile); } catch (IOException e) { log.warn("Problem requesting " + jarFile, e); } }
From source file:to.sven.androidrccar.host.communication.impl.SocketConnector.java
/** * Returns the first non-local IPv4 address of the device. * @return IPv4 address as String or unknown, if no address is found. */// w w w . ja va 2 s . co m private String getLocalIpAddress() { try { for (NetworkInterface iface : Collections.list(NetworkInterface.getNetworkInterfaces())) { for (InetAddress address : Collections.list(iface.getInetAddresses())) { if (!address.isLoopbackAddress() && InetAddressUtils.isIPv4Address(address.getHostAddress())) { return address.getHostAddress().toString(); } } } } catch (SocketException ex) { Log.e(LOG_TAG, ex.toString()); } return dc.getContext().getString(android.R.string.unknownName); }