本文整理汇总了Java中java.net.InetAddress.getAllByName0方法的典型用法代码示例。如果您正苦于以下问题:Java InetAddress.getAllByName0方法的具体用法?Java InetAddress.getAllByName0怎么用?Java InetAddress.getAllByName0使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.net.InetAddress
的用法示例。
在下文中一共展示了InetAddress.getAllByName0方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getIP
import java.net.InetAddress; //导入方法依赖的package包/类
/**
* get IP addresses. Sets invalid to true if we can't get them.
*
*/
void getIP()
throws UnknownHostException
{
if (addresses != null || wildcard || invalid) return;
try {
// now get all the IP addresses
String host;
if (getName().charAt(0) == '[') {
// Literal IPv6 address
host = getName().substring(1, getName().indexOf(']'));
} else {
int i = getName().indexOf(":");
if (i == -1)
host = getName();
else {
host = getName().substring(0,i);
}
}
addresses =
new InetAddress[] {InetAddress.getAllByName0(host, false)[0]};
} catch (UnknownHostException uhe) {
invalid = true;
throw uhe;
} catch (IndexOutOfBoundsException iobe) {
invalid = true;
throw new UnknownHostException(getName());
}
}
示例2: getIP
import java.net.InetAddress; //导入方法依赖的package包/类
/**
* get IP addresses. Sets invalid to true if we can't get them.
*
*/
void getIP()
throws UnknownHostException
{
if (addresses != null || wildcard || invalid) return;
try {
// now get all the IP addresses
String host;
if (getName().charAt(0) == '[') {
// Literal IPv6 address
host = getName().substring(1, getName().indexOf(']'));
} else {
int i = getName().indexOf(':');
if (i == -1)
host = getName();
else {
host = getName().substring(0,i);
}
}
addresses =
new InetAddress[] {InetAddress.getAllByName0(host, false)[0]};
} catch (UnknownHostException uhe) {
invalid = true;
throw uhe;
} catch (IndexOutOfBoundsException iobe) {
invalid = true;
throw new UnknownHostException(getName());
}
}