本文整理汇总了Java中org.apache.commons.validator.routines.InetAddressValidator类的典型用法代码示例。如果您正苦于以下问题:Java InetAddressValidator类的具体用法?Java InetAddressValidator怎么用?Java InetAddressValidator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
InetAddressValidator类属于org.apache.commons.validator.routines包,在下文中一共展示了InetAddressValidator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isValidIpAddress
import org.apache.commons.validator.routines.InetAddressValidator; //导入依赖的package包/类
private boolean isValidIpAddress(String serverIP) {
InetAddressValidator validator = new InetAddressValidator();
return (validator.isValidInet4Address(serverIP) /*
* || validator.
* isValidInet6Address
* (serverIP)
*/);
}
示例2: connectButtonActionPerformed
import org.apache.commons.validator.routines.InetAddressValidator; //导入依赖的package包/类
/**
* Lancia la connessione
*/
private void connectButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_connectButtonActionPerformed
if (!InetAddressValidator.getInstance().isValid(this.ipField.getText()) || Integer.parseInt(portField.getText()) > 65535)
JOptionPane.showMessageDialog(this, "Indirizzo ip non valido", "Errore", JOptionPane.ERROR_MESSAGE);
else {
try {
socket = new Socket();
String ip = ipField.getText();
int port = Integer.parseInt(portField.getText());
socket.connect(new InetSocketAddress(ip, port), 10000);
connectionLabel.setText("Connesso!");
nickname = nicknameField.getText();
//in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
//out = new PrintStream(socket.getOutputStream(), true);
Client client = new Client(socket, nickname);
Thread clientThread = new Thread(client);
clientThread.start();
dispose();
} catch (IOException ex) {
connectionLabel.setText("Errore di connessione");
}
}
}
示例3: isValidInetAddress
import org.apache.commons.validator.routines.InetAddressValidator; //导入依赖的package包/类
public static boolean isValidInetAddress(final String address) {
if (StringUtils.isEmptyOrWhitespaceOnly(address)) {
return false;
}
if (InetAddressValidator.getInstance().isValid(address)) {
return true;
}
return false;
}
示例4: validateState
import org.apache.commons.validator.routines.InetAddressValidator; //导入依赖的package包/类
private void validateState(NetworkInterfaceDescription state) {
if (state.assignment == null) {
state.assignment = IpAssignment.DYNAMIC;
}
Utils.validateState(getStateDescription(), state);
if (state.address != null) {
if (state.assignment != IpAssignment.STATIC) {
throw new IllegalArgumentException(
"IP can be reserved only when assignment is STATIC");
}
if (!InetAddressValidator.getInstance().isValidInet4Address(
state.address)) {
throw new IllegalArgumentException("IP address is invalid");
}
}
}
示例5: isValid
import org.apache.commons.validator.routines.InetAddressValidator; //导入依赖的package包/类
@Override
public boolean isValid(String value, ConstraintValidatorContext context) {
if (value == null) {
return false;
}
return InetAddressValidator
.getInstance()
.isValidInet4Address(value);
}
示例6: isValid
import org.apache.commons.validator.routines.InetAddressValidator; //导入依赖的package包/类
@Override
public boolean isValid(String value, ConstraintValidatorContext context) {
if (value == null) {
return false;
}
return InetAddressValidator
.getInstance()
.isValidInet6Address(value);
}
示例7: replaceUrlParams
import org.apache.commons.validator.routines.InetAddressValidator; //导入依赖的package包/类
public void replaceUrlParams(UrlParams urlParams) {
if (url.contains(RedirectorConstants.HOST_PLACEHOLDER) && urlParams.getIPProtocolVersion() != null) {
// TODO: move to separate place
if (urlParams.getIPProtocolVersion() == IpProtocolVersion.IPV6.getVersion() && StringUtils.isNotBlank(serverIpV6)) {
if (InetAddressValidator.getInstance().isValidInet6Address(serverIpV6)) {
url = url.replace(RedirectorConstants.HOST_PLACEHOLDER, "[" + serverIpV6 + "]");
} else {
url = url.replace(RedirectorConstants.HOST_PLACEHOLDER, serverIpV6);
}
address = serverIpV6;
ipProtocolVersion = IpProtocolVersion.IPV6.getVersion();
} else if (StringUtils.isNotBlank(serverIp)) {
url = url.replace(RedirectorConstants.HOST_PLACEHOLDER, serverIp);
ipProtocolVersion = IpProtocolVersion.IPV4.getVersion();;
}
}
if (urlParams.getPort() != null) {
port = urlParams.getPort();
url = url.replace(RedirectorConstants.PORT_PLACEHOLDER, urlParams.getPort().toString());
}
if (urlParams.getProtocol() != null) {
protocol = urlParams.getProtocol();
url = url.replace(RedirectorConstants.PROTOCOL_PLACEHOLDER, urlParams.getProtocol());
}
if (urlParams.getUrn() != null) {
urn = urlParams.getUrn();
url = url.replace(RedirectorConstants.URN_PLACEHOLDER, urlParams.getUrn());
}
if (urlParams.getAppliedRulesNames() != null) {
appliedUrlRules = urlParams.getAppliedRulesNames();
}
}
示例8: isValidInetAddress
import org.apache.commons.validator.routines.InetAddressValidator; //导入依赖的package包/类
public static boolean isValidInetAddress(final String address) {
if (StringUtils.isEmptyOrWhitespaceOnly(address)) {
return false;
}
if (InetAddressValidator.getInstance().isValid(address)) {
return true;
}
return false;
}
示例9: doSubStageValidateComputeHostState
import org.apache.commons.validator.routines.InetAddressValidator; //导入依赖的package包/类
private void doSubStageValidateComputeHostState(
ProvisionComputeTaskState updatedState) {
// we need to make sure the boot/power services not only properly
// patched
// our sub tasks but also patched the compute host with the IP address
// and other
// runtime data
sendRequest(Operation
.createGet(this, updatedState.computeLink)
.setCompletion((o, e) -> {
if (e != null) {
// the compute host is co-located so it is unexpected
// that it failed the GET
logWarning(() -> String.format("GET to %s failed: %s", o.getUri(),
Utils.toString(e)));
failTask(e);
return;
}
ComputeService.ComputeState chs = o
.getBody(ComputeService.ComputeState.class);
try {
if (!updatedState.isMockRequest) {
InetAddressValidator.getInstance()
.isValidInet4Address(chs.address);
}
sendSelfPatch(TaskStage.FINISHED,
ProvisionComputeTaskState.SubStage.DONE, null);
} catch (Throwable ex) {
failTask(ex);
}
}));
}
示例10: validateState
import org.apache.commons.validator.routines.InetAddressValidator; //导入依赖的package包/类
private void validateState(NetworkInterfaceState state) {
Utils.validateState(getStateDescription(), state);
if (state.address != null) {
if (!InetAddressValidator.getInstance().isValidInet4Address(
state.address)) {
throw new IllegalArgumentException("IP address is invalid");
}
}
if (state.networkLink == null && state.subnetLink == null) {
throw new IllegalArgumentException(
"Either subnetLink or networkLink must be set");
}
}
示例11: isValidIPAddress
import org.apache.commons.validator.routines.InetAddressValidator; //导入依赖的package包/类
/**
* Method to validate an IP address
*
* @param ipAddress IP address to be validated
* @param ipVersion IPv4 or IPv6
*/
public static boolean isValidIPAddress(String ipAddress, IPVersion ipVersion) {
if (StringUtil.isNullOrEmpty(ipAddress)) {
throw new LocalizableValidationException("IP address must be specified",
"subnet.range.ip.must.be.specified");
}
switch (ipVersion) {
case IPv6:
return InetAddressValidator.getInstance().isValidInet6Address(ipAddress);
case IPv4:
default:
return InetAddressValidator.getInstance().isValidInet4Address(ipAddress);
}
}
示例12: isValidIp4
import org.apache.commons.validator.routines.InetAddressValidator; //导入依赖的package包/类
public static boolean isValidIp4(final String ip) {
if (ip == null) {
return false;
}
final InetAddressValidator validator = InetAddressValidator.getInstance();
return validator.isValidInet4Address(ip);
}
示例13: isValidIp6
import org.apache.commons.validator.routines.InetAddressValidator; //导入依赖的package包/类
public static boolean isValidIp6(final String ip) {
if (ip == null) {
return false;
}
final InetAddressValidator validator = InetAddressValidator.getInstance();
return validator.isValidInet6Address(ip);
}
示例14: validateKaaHost
import org.apache.commons.validator.routines.InetAddressValidator; //导入依赖的package包/类
@Override
public void validateKaaHost(String host) throws SandboxServiceException {
if (host == null || host.length() == 0) {
throw new SandboxServiceException("Kaa host field can not be empty!");
} else if (!InetAddressValidator.getInstance().isValid(host) &&
!DomainValidator.getInstance(true).isValid(host)) {
throw new SandboxServiceException("Invalid hostname/ip address format!");
}
}
示例15: isValidNonBlankValue
import org.apache.commons.validator.routines.InetAddressValidator; //导入依赖的package包/类
@Override
public boolean isValidNonBlankValue(String value, ConstraintValidatorContext context) {
switch (type) {
case IP_V4:
return InetAddressValidator.getInstance().isValidInet4Address(value);
case IP_V6:
return InetAddressValidator.getInstance().isValidInet6Address(value);
default:
return InetAddressValidator.getInstance().isValid(value);
}
}