Java Code Examples for org.apache.commons.validator.routines.InetAddressValidator#isValidInet6Address()
The following examples show how to use
org.apache.commons.validator.routines.InetAddressValidator#isValidInet6Address() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NetUtils.java From cosmic with Apache License 2.0 | 5 votes |
public static boolean isValidIp6(final String ip) { if (ip == null) { return false; } final InetAddressValidator validator = InetAddressValidator.getInstance(); return validator.isValidInet6Address(ip); }
Example 2
Source File: RemoteAddressStrategyFactory.java From rocketmq with Apache License 2.0 | 5 votes |
public MultipleRemoteAddressStrategy(String[] strArray) { InetAddressValidator validator = InetAddressValidator.getInstance(); for (String netaddress : strArray) { if (validator.isValidInet4Address(netaddress)) { multipleSet.add(netaddress); } else if (validator.isValidInet6Address(netaddress)) { multipleSet.add(AclUtils.expandIP(netaddress, 8)); } else { throw new AclException(String.format("Netaddress examine Exception netaddress is %s", netaddress)); } } }
Example 3
Source File: RemoteAddressStrategyFactory.java From rocketmq with Apache License 2.0 | 5 votes |
@Override public boolean match(PlainAccessResource plainAccessResource) { InetAddressValidator validator = InetAddressValidator.getInstance(); String whiteRemoteAddress = plainAccessResource.getWhiteRemoteAddress(); if (validator.isValidInet6Address(whiteRemoteAddress)) { whiteRemoteAddress = AclUtils.expandIP(whiteRemoteAddress, 8); } return multipleSet.contains(whiteRemoteAddress); }
Example 4
Source File: RemoteAddressStrategyFactory.java From rocketmq with Apache License 2.0 | 5 votes |
public OneRemoteAddressStrategy(String netaddress) { this.netaddress = netaddress; InetAddressValidator validator = InetAddressValidator.getInstance(); if (!(validator.isValidInet4Address(netaddress) || validator.isValidInet6Address(netaddress))) { throw new AclException(String.format("Netaddress examine Exception netaddress is %s", netaddress)); } }
Example 5
Source File: UtilAll.java From rocketmq with Apache License 2.0 | 5 votes |
private static boolean ipV6Check(byte[] ip) { if (ip.length != 16) { throw new RuntimeException("illegal ipv6 bytes"); } InetAddressValidator validator = InetAddressValidator.getInstance(); return validator.isValidInet6Address(ipToIPv6Str(ip)); }
Example 6
Source File: NetUtils.java From cloudstack with Apache License 2.0 | 5 votes |
public static boolean isValidIp6(final String ip) { if (ip == null) return false; final InetAddressValidator validator = InetAddressValidator.getInstance(); return validator.isValidInet6Address(ip); }
Example 7
Source File: ZKConfig.java From hbase with Apache License 2.0 | 4 votes |
/** * Build the ZK quorum server string with "server:clientport" list, separated by ',' * * @param serverHosts a list of servers for ZK quorum * @param clientPort the default client port * @return the string for a list of "server:port" separated by "," */ public static String buildZKQuorumServerString(String[] serverHosts, String clientPort) { StringBuilder quorumStringBuilder = new StringBuilder(); String serverHost; InetAddressValidator validator = new InetAddressValidator(); for (int i = 0; i < serverHosts.length; ++i) { if (serverHosts[i].startsWith("[")) { int index = serverHosts[i].indexOf("]"); if (index < 0) { throw new IllegalArgumentException(serverHosts[i] + " starts with '[' but has no matching ']:'"); } if (index + 2 == serverHosts[i].length()) { throw new IllegalArgumentException(serverHosts[i] + " doesn't have a port after colon"); } //check the IPv6 address e.g. [2001:db8::1] String serverHostWithoutBracket = serverHosts[i].substring(1, index); if (!validator.isValidInet6Address(serverHostWithoutBracket)) { throw new IllegalArgumentException(serverHosts[i] + " is not a valid IPv6 address"); } serverHost = serverHosts[i]; if ((index + 1 == serverHosts[i].length())) { serverHost = serverHosts[i] + ":" + clientPort; } } else { if (serverHosts[i].contains(":")) { serverHost = serverHosts[i]; // just use the port specified from the input } else { serverHost = serverHosts[i] + ":" + clientPort; } } if (i > 0) { quorumStringBuilder.append(','); } quorumStringBuilder.append(serverHost); } return quorumStringBuilder.toString(); }
Example 8
Source File: AppiumServiceBuilder.java From java-client with Apache License 2.0 | 4 votes |
@Override protected ImmutableList<String> createArgs() { List<String> argList = new ArrayList<>(); loadPathToMainScript(); argList.add(appiumJS.getAbsolutePath()); argList.add("--port"); argList.add(String.valueOf(getPort())); if (StringUtils.isBlank(ipAddress)) { ipAddress = BROADCAST_IP_ADDRESS; } else { InetAddressValidator validator = InetAddressValidator.getInstance(); if (!validator.isValid(ipAddress) && !validator.isValidInet4Address(ipAddress) && !validator.isValidInet6Address(ipAddress)) { throw new IllegalArgumentException( "The invalid IP address " + ipAddress + " is defined"); } } argList.add("--address"); argList.add(ipAddress); File log = getLogFile(); if (log != null) { argList.add("--log"); argList.add(log.getAbsolutePath()); } Set<Map.Entry<String, String>> entries = serverArguments.entrySet(); for (Map.Entry<String, String> entry : entries) { String argument = entry.getKey(); String value = entry.getValue(); if (StringUtils.isBlank(argument) || value == null) { continue; } argList.add(argument); if (!StringUtils.isBlank(value)) { argList.add(value); } } if (capabilities != null) { argList.add("--default-capabilities"); argList.add(capabilitiesToCmdlineArg()); } return new ImmutableList.Builder<String>().addAll(argList).build(); }