Java 8 InetAddress - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 InetAddress class.

This code example shows how to use the following methods:getAddress, isAnyLocalAddress, isLinkLocalAddress, isLoopbackAddress, isMulticastAddress
	 * [Oracle|Open]JDK up to 8 contains obsolete check for site-local ipv6 
	 * addresses, this repaces it with correct one. 
	 */ 
	public static boolean isSiteLocalAddress(InetAddress i) {
	    if(i instanceof Inet6Address) {
			byte [] addr = i.getAddress();
			assert(addr.length == 128/8);
			// XXX what about ipv6-mapped ipv4 site-local addresses? 
			// (weird/insane/not-sure-if-possible-but) 
			/* 
			try { 
				if(addr[0] == (byte)0x20 && addr[1] == (byte)0x02) { 
					// 2002::/16, 6to4 tunnels 
					return InetAddress.getByAddress( 
						Arrays.copyOfRange(addr,2,6)).isSiteLocalAddress(); 
				} 
				if(addr[ 0] == (byte)0 && addr[ 1] == (byte)0 && 
				   addr[ 2] == (byte)0 && addr[ 3] == (byte)0 && 
				   addr[ 4] == (byte)0 && addr[ 5] == (byte)0 && 
				   addr[ 6] == (byte)0 && addr[ 7] == (byte)0 && 

8
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getAddress, isAnyLocalAddress, isLinkLocalAddress, isLoopbackAddress, isMulticastAddress
 *  
 * You should have received a copy of the GNU General Public License 
 * along with this program; if not, write to the Free Software 
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
 */ 
 
package freenet.io.comm; 
 
import java.io.DataInput; 
import java.io.DataOutputStream; 
import java.io.IOException; 
import java.net.InetAddress; 
import java.net.UnknownHostException; 
 
import freenet.io.WritableToDataOutputStream; 
import freenet.support.transport.ip.HostnameSyntaxException; 
import freenet.support.transport.ip.IPUtil; 
 
/** 
 * @author ian 

8
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getHostAddress
		} 
	} 
 
	@Override 
	public void onPiFoundAtAddress(InetAddress addr) {
		piUrl = "http://" + addr.getHostAddress() + "/";
		webView.loadUrl("file:///android_asset/connected.html");
		piup = new PiUptimeTask(this);
		piup.doInBackground(addr);
	} 
 
	@Override 
	public void onStatusUpdate(String status) {
		ActionBar ab = getActionBar();
		status = status.replace("load average", "load");
		status = status.replace("users", "u");
		ab.setTitle(status.substring(status.indexOf("up")));
	} 
 
	@Override 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:equals
        }); 
    } 
 
    public int compareEndpoints(InetAddress address, InetAddress a1, InetAddress a2)
    { 
        if (address.equals(a1) && !address.equals(a2))
            return -1; 
        if (address.equals(a2) && !address.equals(a1))
            return 1; 
 
        String addressRack = getRack(address);
        String a1Rack = getRack(a1);
        String a2Rack = getRack(a2);
        if (addressRack.equals(a1Rack) && !addressRack.equals(a2Rack))
            return -1; 
        if (addressRack.equals(a2Rack) && !addressRack.equals(a1Rack))
            return 1; 
 
        String addressDatacenter = getDatacenter(address);
        String a1Datacenter = getDatacenter(a1);

6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getHostName, getHostAddress
    } 
 
    @Override 
    public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) {
        Inet4Address addr = (Inet4Address) source;
        writer.setValue(addr.getHostName()+"/"+addr.getHostAddress());
    } 
 
    @Override 
    public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
        String hostSlashAddress = reader.getValue();
        int i = hostSlashAddress.indexOf('/');
        try { 
            if (i==-1) {
                return Inet4Address.getByName(hostSlashAddress);
            } else { 
                String host = hostSlashAddress.substring(0, i);
                String addrS = hostSlashAddress.substring(i+1);
                byte[] addr = new byte[4];
                String[] addrSI = addrS.split("\\.");
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:isLoopbackAddress, toString
	ia = InetAddress.getByName("");
	System.out.println("\"\" = " + check(ia));
 
	ia = InetAddress.getByName("localhost");
	System.out.println("localhost = " + check(ia));
	if( !ia.isLoopbackAddress() )
	{ 
	    System.out.println("Not a loopback?");
	} 
    } 
 
    private static String check(InetAddress ia)
         throws Throwable 
    { 
	if (ia instanceof Inet6Address) {
	    if (ia.toString().equals("localhost/::::::::1") ||
		ia.toString().equals("localhost/0:0:0:0:0:0:0:1")) {
		return "localhost/127.0.0.1"; 
	    } 
	} 

6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getHostName
      } 
    } 
 
    public static String getHostName(InetAddress ia)
    { 
       return ia.getHostName();
    } 
 
} 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getHostAddress
    } 
 
 
    public static String normalizeHostAddress(final InetAddress localHost) {
        if (localHost instanceof Inet6Address) {
            return "[" + localHost.getHostAddress() + "]";
        } 
        else { 
            return localHost.getHostAddress();
        } 
    } 
 
} 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getClass, getAddress, getCanonicalHostName, getHostAddress, getHostName
			System.out.println(iface);
		} 
	} 
 
	private static void printAddress(InetAddress address) {
		System.out.println(address.getClass());
		System.out.println(Arrays.toString(address.getAddress()));
		System.out.println(address.getHostAddress());
		System.out.println(address.getHostName());
		System.out.println(address.getCanonicalHostName());
	} 
} 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getHostAddress
	public final InetAddress addr;
	 
	@Override 
	public SimpleFieldSet toFieldSet() { 
		SimpleFieldSet fs = super.toFieldSet();
		fs.putOverwrite("Address", addr.getHostAddress());
		return fs;
	} 
	 
	public InetAddressAddressTrackerItem(SimpleFieldSet fs) throws FSParseException {
		super(fs);
		try { 
			addr = InetAddress.getByName(fs.getString("Address"));
		} catch (UnknownHostException e) {
			throw (FSParseException)new FSParseException("Unknown domain name in Address: "+e).initCause(e);
		} 
	} 
 
} 
6
CodeRank
Experience pair programming with AI  Get Codota for Java

Related Java 8 InetAddress Questions & Answers:

See Code Examples for Java 8 InetAddress Methods: