Java 8 InterfaceAddress - 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 InterfaceAddress class.

This code example shows how to use the following methods:getAddress, getNetworkPrefixLength
        if (!passed)
            throw new RuntimeException("Failed: some interfaces have invalid prefix lengths");
    } 
 
    static boolean checkPrefix(InterfaceAddress iaddr) {
        InetAddress addr = iaddr.getAddress();
 
        if (addr instanceof Inet4Address)
            return checkIPv4PrefixLength(iaddr.getNetworkPrefixLength());
        else 
            return checkIPv6PrefixLength(iaddr.getNetworkPrefixLength());
    } 
 
    static boolean checkIPv4PrefixLength(int prefix) {
        if (prefix >=0 && prefix <= 32)
            return true; 
 
        return false; 
    } 
 
6
CodeRank
This code example shows how to use the following methods:getAddress, getBroadcast
     *  
     * @since 1.6 
     */ 
    public void test_getBroadcast() { 
        if (interfaceAddr != null) {
            InetAddress addr = interfaceAddr.getAddress();
            InetAddress addr1 = interfaceAddr.getBroadcast();
            InetAddress addr2 = anotherInterfaceAddr.getBroadcast();
            if (addr instanceof Inet4Address) {
                assertEquals(addr2, addr1);
            } else if (addr instanceof Inet6Address) {
                assertNull(addr1);
                assertNull(addr2);
            } 
        } 
    } 
 
    /** 
     * @tests java.net.InterfaceAddress.getNetworkPrefixLength() 
     *  
5
CodeRank
This code example shows how to use the following methods:equals
 
        ia1.equals(null);
    } 
 
    static void compare(InterfaceAddress ia1, InterfaceAddress ia2, boolean equal) {
        if (ia1.equals(ia2) != equal)
            throw new RuntimeException("Failed: " + ia1 + " not equals to " + ia2);
 
        if (ia2.equals(ia1) != equal)
            throw new RuntimeException("Failed: " + ia2 + " not equals to " + ia1);
    } 
 
    /** 
     * Returns an InterfaceAddress instance with its fields set the the values 
     * specificed. 
     */ 
    static InterfaceAddress createInterfaceAddress(
                InetAddress address, InetAddress broadcast, short prefixlength) {
        try { 
            Class<InterfaceAddress> IAClass = InterfaceAddress.class;
5
CodeRank
This code example shows how to use the following methods:getAddress, getNetworkPrefixLength
        if (!passed)
            throw new RuntimeException("Failed: some interfaces have invalid prefix lengths");
    } 
 
    static boolean checkPrefix(InterfaceAddress iaddr) {
        InetAddress addr = iaddr.getAddress();
 
        if (addr instanceof Inet4Address)
            return checkIPv4PrefixLength(iaddr.getNetworkPrefixLength());
        else 
            return checkIPv6PrefixLength(iaddr.getNetworkPrefixLength());
    } 
 
    static boolean checkIPv4PrefixLength(int prefix) {
        if (prefix >=0 && prefix <= 32)
            return true; 
 
        return false; 
    } 
 
5
CodeRank
This code example shows how to use the following methods:getAddress, getNetworkPrefixLength
  public InetAddress getAddress(InterfaceAddress ifaddr)
  { 
    if (ifaddr == null)
      return null; 
 
    return ifaddr.getAddress();
  } 
 
  public InetAddress getAddress()
  { 
    return getAddress(getInterfaceAddress()); 
  } 
 
  public InetAddress getApAddress()
  { 
    return getAddress(getApInterface()); 
  } 
 
  public InetAddress getWiFiAddress()
  { 

4
CodeRank

Related Java 8 InterfaceAddress Questions & Answers:

See Code Examples for Java 8 InterfaceAddress Methods: