当前位置: 首页>>代码示例>>Java>>正文


Java NetworkInterface.equals方法代码示例

本文整理汇总了Java中java.net.NetworkInterface.equals方法的典型用法代码示例。如果您正苦于以下问题:Java NetworkInterface.equals方法的具体用法?Java NetworkInterface.equals怎么用?Java NetworkInterface.equals使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.net.NetworkInterface的用法示例。


在下文中一共展示了NetworkInterface.equals方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import java.net.NetworkInterface; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {

        boolean passed = true;
        try {
            MulticastSocket ms = new MulticastSocket();
            Enumeration<NetworkInterface> networkInterfaces = NetworkInterface
                    .getNetworkInterfaces();
            while (networkInterfaces.hasMoreElements()) {
                NetworkInterface netIf = networkInterfaces.nextElement();
                if (isNetworkInterfaceTestable(netIf)) {
                    printNetIfDetails(netIf);
                    ms.setNetworkInterface(netIf);
                    NetworkInterface msNetIf = ms.getNetworkInterface();
                    if (netIf.equals(msNetIf)) {
                        System.out.println(" OK");
                    } else {
                        System.out.println("FAILED!!!");
                        printNetIfDetails(msNetIf);
                        passed = false;
                    }
                    System.out.println("------------------");
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
            passed = false;
        }
        if (!passed) {
            throw new RuntimeException("Test Fail");
        }
        System.out.println("Test passed ");
    }
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:33,代码来源:SetGetNetworkInterfaceTest.java

示例2: assertNetworkInterfaceEqual

import java.net.NetworkInterface; //导入方法依赖的package包/类
static void assertNetworkInterfaceEqual(
        NetworkInterface expectedNetworkInterface,
        NetworkInterface deserializedNetworkInterface) {
    System.err
            .println("Inet6AddressSerializationTest.assertNetworkInterfaceEqual:");
    if (expectedNetworkInterface == null) {
        if (deserializedNetworkInterface == null) {
            // ok, do nothing.
            System.err.println("Network Interface equality "
                    + " NetworkInterface, expected:"
                    + expectedNetworkInterface + ", got :"
                    + deserializedNetworkInterface);
        } else {
            System.err.println("Error checking "
                    + " NetworkInterface, expected:"
                    + expectedNetworkInterface + ", got :"
                    + deserializedNetworkInterface);
            failed = true;
        }
    } else if (!expectedNetworkInterface
            .equals(deserializedNetworkInterface)) {
        System.err.println("Error checking "
                + // versionStr +
                " NetworkInterface, expected:" + expectedNetworkInterface
                + ", got :" + deserializedNetworkInterface);
        failed = true;
    } else {
        System.err.println("Network Interface equality "
                + " NetworkInterface, expected:" + expectedNetworkInterface
                + ", got :" + deserializedNetworkInterface);
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:33,代码来源:Inet6AddressSerializationTest.java

示例3: main

import java.net.NetworkInterface; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
    int checkFailureCount = 0;

    try {
        Enumeration<NetworkInterface> en = NetworkInterface
                .getNetworkInterfaces();
        while (en.hasMoreElements()) {
            NetworkInterface ni = en.nextElement();
            Enumeration<InetAddress> addrs = ni.getInetAddresses();
            System.out.println("############ Checking network interface + "
                    + ni + " #############");
            while (addrs.hasMoreElements()) {
                InetAddress addr = addrs.nextElement();
                System.out.println("************ Checking address  + "
                        + addr + " *************");
                NetworkInterface addrNetIf = NetworkInterface
                        .getByInetAddress(addr);
                if (addrNetIf.equals(ni)) {
                    System.out.println("Retreived net if " + addrNetIf
                            + " equal to owning net if " + ni);
                } else {
                    System.out.println("Retreived net if " + addrNetIf
                            + "NOT  equal to owning net if " + ni
                            + "***********");
                    checkFailureCount++;
                }

            }
        }

    } catch (Exception ex) {

    }

    if (checkFailureCount > 0) {
        throw new RuntimeException(
                "NetworkInterface lookup by address didn't match owner network interface");
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:40,代码来源:NetworkInterfaceRetrievalTests.java


注:本文中的java.net.NetworkInterface.equals方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。