List of usage examples for java.net InetAddress getByAddress
public static InetAddress getByAddress(byte[] addr) throws UnknownHostException
From source file:com.linkedin.urls.HostNormalizer.java
private void normalizeHost() { if (StringUtils.isEmpty(_host)) { return;//from w w w.j ava 2 s.c om } String host; try { //replace high unicode characters host = IDN.toASCII(_host); } catch (IllegalArgumentException ex) { //occurs when the url is invalid. Just return return; } host = host.toLowerCase(); host = UrlUtil.decode(host); _bytes = tryDecodeHostToIp(host); if (_bytes != null) { InetAddress address; try { address = InetAddress.getByAddress(_bytes); String ipAddress = address.getHostAddress(); if (address instanceof Inet6Address) { host = "[" + ipAddress + "]"; } else { host = ipAddress; } } catch (UnknownHostException e) { return; } } if (StringUtils.isEmpty(host)) { return; } host = UrlUtil.removeExtraDots(host); _normalizedHost = UrlUtil.encode(host).replace("\\x", "%"); }
From source file:org.npr.android.test.HttpServer.java
/** * Prepare the server to start./* w ww .j av a 2 s.co m*/ * * This only needs to be called once per instance. Once initialized, the * server can be started and stopped as needed. */ public void init() { try { socket = new ServerSocket(port, 0, InetAddress.getByAddress(new byte[] { 127, 0, 0, 1 })); socket.setSoTimeout(5000); port = socket.getLocalPort(); Log.d(TAG, "Server stated at " + socket.getInetAddress().getHostAddress() + ":" + port); } catch (UnknownHostException e) { Log.e(TAG, "Error initializing server", e); } catch (IOException e) { Log.e(TAG, "Error initializing server", e); } }
From source file:com.oakesville.mythling.util.MediaStreamProxy.java
public void init() throws IOException { localhost = InetAddress.getByAddress(new byte[] { 127, 0, 0, 1 }); socket = new ServerSocket(port, 0, localhost); socket.setSoTimeout(5000); // TODO hardcoded port = socket.getLocalPort();//ww w .j a v a2 s. c o m }
From source file:nl.minvenj.pef.util.TestUtil.java
/** * Convert an integer representing an IPv4 address to its dotted decimal format. * * @param ip the int containing the IP data * @return a dotted decimal IPv4 String/*from w w w . j av a 2 s .c o m*/ */ public static String ipv4StringFromInt(final int ip) { try { final byte[] ipBytes = ByteBuffer.allocate(4).putInt(ip).array(); final InetAddress foo = InetAddress.getByAddress(ipBytes); return foo.getHostAddress(); } catch (final UnknownHostException e) { throw new IllegalArgumentException(e); } }
From source file:net.fenyo.gnetwatch.GenericTools.java
/** * Converts an IP address to its string representation. * @param addr ipv4 address./*from w w w . j a v a 2 s. c o m*/ * @return String ascii representation. */ static public String inet4AddressToString(final Inet4Address addr) { try { byte bytes[] = addr.getAddress(); return InetAddress.getByAddress(bytes).toString().substring(1); } catch (final UnknownHostException ex) { log.error("Exception", ex); } return ""; }
From source file:org.openhab.binding.network.service.NetworkUtils.java
/** * Converts 32 bits int to IPv4 <tt>InetAddress</tt>. * * @param val int representation of IPv4 address * @return the address object// w ww .jav a2s . c o m */ public static final InetAddress int2InetAddress(int val) { byte[] value = { (byte) ((val & 0xFF000000) >>> 24), (byte) ((val & 0X00FF0000) >>> 16), (byte) ((val & 0x0000FF00) >>> 8), (byte) ((val & 0x000000FF)) }; try { return InetAddress.getByAddress(value); } catch (UnknownHostException e) { return null; } }
From source file:com.meh.CopyProxy.java
public void init() { try {//w w w. ja va2 s. com socket = new ServerSocket(port, 0, InetAddress.getByAddress(new byte[] { 127, 0, 0, 1 })); socket.setSoTimeout(5000); port = socket.getLocalPort(); Log.d(tag, "port " + port + " obtained"); } catch (UnknownHostException e) { Log.e(tag, "Error initializing server", e); } catch (IOException e) { Log.e(tag, "Error initializing server", e); } }
From source file:audio.StreamProxy.java
public void init() { try {/*from w w w . j a v a 2 s.co m*/ socket = new ServerSocket(port, 0, InetAddress.getByAddress(new byte[] { 127, 0, 0, 1 })); socket.setSoTimeout(5000); port = socket.getLocalPort(); Log.d(LOG_TAG, "port " + port + " obtained"); } catch (UnknownHostException e) { Log.e(LOG_TAG, "Error initializing server", e); } catch (IOException e) { Log.e(LOG_TAG, "Error initializing server", e); } }
From source file:com.arthur.pervasivenfc.ExecuteActivity.StreamProxy.java
public void init() { try {//from w w w . j a va 2s. c om socket = new ServerSocket(port, 0, InetAddress.getByAddress(new byte[] { 127, 0, 0, 1 })); //socket = new ServerSocket(port); //socket.setSoTimeout(5000); port = socket.getLocalPort(); Log.d(LOG_TAG, "port " + port + " obtained"); } catch (UnknownHostException e) { Log.e(LOG_TAG, "Error initializing server", e); } catch (IOException e) { Log.e(LOG_TAG, "Error initializing server", e); } }
From source file:com.code.android.vibevault.StreamProxy.java
public void init() { try {// w w w . j av a 2 s.com socket = new ServerSocket(port, 0, InetAddress.getByAddress(new byte[] { 127, 0, 0, 1 })); socket.setSoTimeout(5000); port = socket.getLocalPort(); } catch (UnknownHostException e) { Log.e(LOG_TAG, "Error initializing server", e); } catch (IOException e) { Log.e(LOG_TAG, "Error initializing server", e); } }