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

This code example shows how to use the following methods:getName
        if (loopbackAddress == null) {
            return; 
        } 
 
        InetAddressMatchInterfaceCriteria criteria = new InetAddressMatchInterfaceCriteria("::1");
        assertEquals(loopbackAddress, criteria.isAcceptable(loopbackInterface, loopbackAddress));
        criteria = new InetAddressMatchInterfaceCriteria("::1%" + loopbackInterface.getName());
        if (loopbackAddress.getScopeId() > 0) {
            assertEquals(loopbackAddress, criteria.isAcceptable(loopbackInterface, loopbackAddress));
        } else { 
            InetAddress match = criteria.isAcceptable(loopbackInterface, loopbackAddress);
            if (!loopbackAddress.equals(match)) {
                // This match fails because ::1%lo becomes ::1%<number_of_lo> which isn't 0 
                assertNull(match + " is invalid", criteria.isAcceptable(loopbackInterface, loopbackAddress));
            } 
        } 
        criteria = new InetAddressMatchInterfaceCriteria("::1%" + loopbackAddress.getScopeId());
        assertEquals(loopbackAddress, criteria.isAcceptable(loopbackInterface, loopbackAddress));
        criteria = new InetAddressMatchInterfaceCriteria("::1%" + (loopbackAddress.getScopeId() + 1));
        assertNull(criteria.isAcceptable(loopbackInterface, loopbackAddress));

8
CodeRank
This code example shows how to use the following methods:isLoopback
     * @return <code>address</code> if {@link NetworkInterface#isLoopback()} is true, null otherwise. 
     */ 
    @Override 
    protected InetAddress isAcceptable(NetworkInterface networkInterface, InetAddress address) throws SocketException {
 
        if( networkInterface.isLoopback() )
            return address;
        return null; 
    } 
 
    private Object readResolve() throws ObjectStreamException {
        return INSTANCE;
    } 
} 
7
CodeRank
This code example shows how to use the following methods:isPointToPoint
     *         {@link NetworkInterface#isPointToPoint() point-to-point interface}. 
     */ 
    @Override 
    protected InetAddress isAcceptable(NetworkInterface networkInterface, InetAddress address) throws SocketException {
 
        if( networkInterface.isPointToPoint() )
            return address;
        return null; 
    } 
 
    private Object readResolve() throws ObjectStreamException {
        return INSTANCE;
    } 
} 
7
CodeRank
This code example shows how to use the following methods:getName
     *          equals <code>networkInterface</code>'s {@link NetworkInterface#getName() name}. 
     */ 
    @Override 
    protected InetAddress isAcceptable(NetworkInterface networkInterface, InetAddress address) throws SocketException {
 
        if( name.equals(networkInterface.getName()) )
            return address;
        return null; 
    } 
 
    @Override 
    public int hashCode() { 
        return name.hashCode();
    } 
 
    @Override 
    public boolean equals(Object o) {
        return (o instanceof NicInterfaceCriteria)
                && name.equals(((NicInterfaceCriteria)o).name);
    } 
7
CodeRank
This code example shows how to use the following methods:isUp
     *         {@link NetworkInterface#isUp() up} 
     */ 
    @Override 
    protected InetAddress isAcceptable(NetworkInterface networkInterface, InetAddress address) throws SocketException {
 
        if( networkInterface.isUp() )
            return address;
        return null; 
    } 
 
    private Object readResolve() throws ObjectStreamException {
        return INSTANCE;
    } 
} 
7
CodeRank
This code example shows how to use the following methods:supportsMulticast
     *         {@link NetworkInterface#supportsMulticast() supports multicast}. 
     */ 
    @Override 
    protected InetAddress isAcceptable(NetworkInterface networkInterface, InetAddress address) throws SocketException {
 
        if( networkInterface.supportsMulticast() )
            return address;
        return null; 
    } 
 
    private Object readResolve() throws ObjectStreamException {
        return INSTANCE;
    } 
} 
7
CodeRank
This code example shows how to use the following methods:getName
     *          matches <code>networkInterface</code>'s {@link NetworkInterface#getName() name}. 
     */ 
    @Override 
    protected InetAddress isAcceptable(NetworkInterface networkInterface, InetAddress address) throws SocketException {
 
        if( pattern.matcher(networkInterface.getName()).matches() )
            return address;
        return null; 
    } 
 
    @Override 
    public int hashCode() { 
        return pattern.toString().hashCode();
    } 
 
    @Override 
    public boolean equals(Object o) {
        return (o instanceof NicMatchInterfaceCriteria)
                && pattern.toString().equals(((NicMatchInterfaceCriteria)o).pattern.toString());
    } 
7
CodeRank
This code example shows how to use the following methods:isVirtual
     *         {@link NetworkInterface#isVirtual() virtual} 
     */ 
    @Override 
    protected InetAddress isAcceptable(NetworkInterface networkInterface, InetAddress address) throws SocketException {
 
        if (networkInterface.isVirtual())
            return address;
        return null; 
    } 
 
    private Object readResolve() throws ObjectStreamException {
        return INSTANCE;
    } 
} 
7
CodeRank
This code example shows how to use the following methods:isLoopback
     */ 
    @Override 
    protected InetAddress isAcceptable(NetworkInterface networkInterface, InetAddress address) throws SocketException {
 
        try { 
            if( networkInterface.isLoopback() ) {
                return getAddress(); 
            } 
        } catch (UnknownHostException e) {
            // One time only log a warning 
            if (!unknownHostLogged) {
                SERVER_LOGGER.cannotResolveAddress(this.address);
                unknownHostLogged = true;
            } 
        } 
        return null; 
    } 
 
    public String toString() {
        StringBuilder sb = new StringBuilder("LoopbackAddressInterfaceCriteria(");
7
CodeRank
This code example shows how to use the following methods:getDisplayName
    public static boolean useInterface(NetworkInterface theInterface) {
        boolean result = true;
        String platform = System.getProperty("os.name");
        // only use these on windows platforms 
        if (platform.startsWith("Windows")) {
            if ((theInterface.getDisplayName()
                    .equals("Teredo Tunneling Pseudo-Interface"))
                    || (theInterface.getDisplayName()
                            .equals("6to4 Tunneling Pseudo-Interface"))
                    || (theInterface.getDisplayName()
                            .equals("Automatic Tunneling Pseudo-Interface"))
                    || (theInterface.getDisplayName()
                            .equals("Loopback Pseudo-Interface"))) {
                result = false;
            } 
        } 
        return result;
    } 
} 
5
CodeRank

Related Java 8 NetworkInterface Questions & Answers:

See Code Examples for Java 8 NetworkInterface Methods: