List of usage examples for org.apache.http.conn.util InetAddressUtils isIPv6Address
public static boolean isIPv6Address(final String input)
From source file:nl.verheulconsultants.monitorisp.service.Utilities.java
/** * Use the org.apache.httpcomponents class library to validate Ip4 and Ip6 addresses. * * @param ip the ip// w ww.jav a 2s .c o m * @return check if the ip is valid ipv4 or ipv6 */ private static boolean isValidIp(final String ip) { return InetAddressUtils.isIPv4Address(ip) || InetAddressUtils.isIPv6Address(ip); }
From source file:org.mariotaku.twidere.util.net.HostResolvedSocketFactory.java
@Override public Socket createSocket(String host, int port, InetAddress localHost, int localPort) throws IOException { final String resolvedHost = resolver.resolve(host); if (resolvedHost != null && !resolvedHost.equals(host)) { if (InetAddressUtils.isIPv6Address(resolvedHost)) { final byte[] resolvedAddress = Inet6Address.getByName(resolvedHost).getAddress(); return new Socket(InetAddress.getByAddress(host, resolvedAddress), port); } else if (InetAddressUtils.isIPv4Address(resolvedHost)) { final byte[] resolvedAddress = Inet4Address.getByName(resolvedHost).getAddress(); return new Socket(InetAddress.getByAddress(host, resolvedAddress), port); }// w ww .ja va 2 s. com } return defaultFactory.createSocket(host, port, localHost, localPort); }
From source file:com.connectsdk.core.Util.java
public static boolean isIPv6Address(String ipAddress) { return InetAddressUtils.isIPv6Address(ipAddress); }
From source file:org.elasticsearch.test.rest.client.StrictHostnameVerifier.java
private String stripBracketsIfNecessary(String host) { if (host.startsWith("[") && host.endsWith("]")) { String newHost = host.substring(1, host.length() - 1); assert InetAddressUtils.isIPv6Address(newHost); return newHost; }//from w ww . j a v a 2s .co m return host; }
From source file:org.mariotaku.twidere.util.net.HostResolvedSocketFactory.java
@Override public Socket createSocket(InetAddress host, int port) throws IOException { final String hostName = host.getHostName(); final String resolvedHost = resolver.resolve(hostName); if (resolvedHost != null && !resolvedHost.equals(hostName)) { if (InetAddressUtils.isIPv6Address(resolvedHost)) { final byte[] resolvedAddress = Inet6Address.getByName(resolvedHost).getAddress(); return new Socket(InetAddress.getByAddress(hostName, resolvedAddress), port); } else if (InetAddressUtils.isIPv4Address(resolvedHost)) { final byte[] resolvedAddress = Inet4Address.getByName(resolvedHost).getAddress(); return new Socket(InetAddress.getByAddress(hostName, resolvedAddress), port); }/*from w w w . j a v a 2 s . c om*/ } return defaultFactory.createSocket(host, port); }
From source file:com.android.idtt.http.client.util.URIBuilder.java
private String buildString() { StringBuilder sb = new StringBuilder(); if (this.scheme != null) { sb.append(this.scheme).append(':'); }/*from ww w. j a va2 s.c o m*/ if (this.encodedSchemeSpecificPart != null) { sb.append(this.encodedSchemeSpecificPart); } else { if (this.encodedAuthority != null) { sb.append("//").append(this.encodedAuthority); } else if (this.host != null) { sb.append("//"); if (this.encodedUserInfo != null) { sb.append(this.encodedUserInfo).append("@"); } else if (this.userInfo != null) { sb.append(encodeUserInfo(this.userInfo)).append("@"); } if (InetAddressUtils.isIPv6Address(this.host)) { sb.append("[").append(this.host).append("]"); } else { sb.append(this.host); } if (this.port >= 0) { sb.append(":").append(this.port); } } if (this.encodedPath != null) { sb.append(normalizePath(this.encodedPath)); } else if (this.path != null) { sb.append(encodePath(normalizePath(this.path))); } if (this.encodedQuery != null) { sb.append("?").append(this.encodedQuery); } else if (this.queryParams != null) { sb.append("?").append(encodeQuery(this.queryParams)); } } if (this.encodedFragment != null) { sb.append("#").append(this.encodedFragment); } else if (this.fragment != null) { sb.append("#").append(encodeFragment(this.fragment)); } return sb.toString(); }
From source file:org.apache.tajo.validation.NetworkAddressValidator.java
@Override protected <T> boolean validateInternal(T object) { boolean result = false; if (object != null) { if (object instanceof CharSequence) { String valueString = object.toString(); if (valueString.isEmpty()) { result = true;/*from ww w . j ava 2s . co m*/ } else { int separatorIdx = valueString.indexOf(':'); String hostOrIpAddress = null; if (separatorIdx > -1) { if (valueString.indexOf(':', separatorIdx + 1) > -1) { // it is IPV6 representation. int leftBracketsIdx = valueString.indexOf('['); int rightBracketsIdx = valueString.indexOf(']'); int periodIdx = valueString.indexOf('.'); if ((leftBracketsIdx > -1) && (rightBracketsIdx > -1) && (valueString.length() > (rightBracketsIdx + 1)) && valueString.charAt(rightBracketsIdx + 1) == ':') { hostOrIpAddress = valueString.substring(leftBracketsIdx + 1, rightBracketsIdx); separatorIdx = rightBracketsIdx + 1; } else if ((periodIdx > -1)) { hostOrIpAddress = valueString.substring(0, periodIdx); separatorIdx = periodIdx; } else { separatorIdx = valueString.lastIndexOf(':'); hostOrIpAddress = valueString.substring(0, separatorIdx); } } else { hostOrIpAddress = valueString.substring(0, separatorIdx); } } else { hostOrIpAddress = valueString; } result = ((hostnamePattern.matcher(hostOrIpAddress).find()) | InetAddressUtils.isIPv4Address(hostOrIpAddress) | InetAddressUtils.isIPv6Address(hostOrIpAddress)); if (separatorIdx > -1) { result &= portNumberPattern.matcher(valueString.substring(separatorIdx + 1)).find(); } } } } else { result = true; } return result; }
From source file:cn.isif.util_plus.http.client.util.URIBuilder.java
private String buildString(Charset charset) { final StringBuilder sb = new StringBuilder(); if (this.scheme != null) { sb.append(this.scheme).append(':'); }// www . j av a 2 s.c om if (this.encodedSchemeSpecificPart != null) { sb.append(this.encodedSchemeSpecificPart); } else { if (this.encodedAuthority != null) { sb.append("//").append(this.encodedAuthority); } else if (this.host != null) { sb.append("//"); if (this.encodedUserInfo != null) { sb.append(this.encodedUserInfo).append("@"); } else if (this.userInfo != null) { sb.append(encodeUserInfo(this.userInfo, charset)).append("@"); } if (InetAddressUtils.isIPv6Address(this.host)) { sb.append("[").append(this.host).append("]"); } else { sb.append(this.host); } if (this.port >= 0) { sb.append(":").append(this.port); } } if (this.encodedPath != null) { sb.append(normalizePath(this.encodedPath)); } else if (this.path != null) { sb.append(encodePath(normalizePath(this.path), charset)); } if (this.encodedQuery != null) { sb.append("?").append(this.encodedQuery); } else if (this.queryParams != null) { sb.append("?").append(encodeQuery(this.queryParams, charset)); } } if (this.encodedFragment != null) { sb.append("#").append(this.encodedFragment); } else if (this.fragment != null) { sb.append("#").append(encodeFragment(this.fragment, charset)); } return sb.toString(); }
From source file:com.gistlabs.mechanize.util.apache.URIBuilder.java
private String buildString() { StringBuilder sb = new StringBuilder(); if (this.scheme != null) sb.append(this.scheme).append(':'); if (this.encodedSchemeSpecificPart != null) sb.append(this.encodedSchemeSpecificPart); else {/* w w w.j a va 2s . c o m*/ if (this.encodedAuthority != null) sb.append("//").append(this.encodedAuthority); else if (this.host != null) { sb.append("//"); if (this.encodedUserInfo != null) sb.append(this.encodedUserInfo).append("@"); else if (this.userInfo != null) sb.append(encodeUserInfo(this.userInfo)).append("@"); if (InetAddressUtils.isIPv6Address(this.host)) sb.append("[").append(this.host).append("]"); else sb.append(this.host); if (this.port >= 0) sb.append(":").append(this.port); } if (this.encodedPath != null) sb.append(normalizePath(this.encodedPath)); else if (this.path != null) sb.append(encodePath(normalizePath(this.path))); if (this.encodedQuery != null) sb.append("?").append(this.encodedQuery); else if (this.queryParams != null) sb.append("?").append(encodeQuery(this.queryParams)); } if (this.encodedFragment != null) sb.append("#").append(this.encodedFragment); else if (this.fragment != null) sb.append("#").append(encodeFragment(this.fragment)); return sb.toString(); }
From source file:org.mariotaku.twidere.util.net.HostResolvedSocketFactory.java
@Override public Socket createSocket(InetAddress address, int port, InetAddress localAddress, int localPort) throws IOException { final String hostName = address.getHostName(); final String resolvedHost = resolver.resolve(hostName); if (resolvedHost != null && !resolvedHost.equals(hostName)) { if (InetAddressUtils.isIPv6Address(resolvedHost)) { final byte[] resolvedAddress = Inet6Address.getByName(resolvedHost).getAddress(); return new Socket(InetAddress.getByAddress(hostName, resolvedAddress), port, localAddress, localPort);/*from w ww .ja va 2 s . c o m*/ } else if (InetAddressUtils.isIPv4Address(resolvedHost)) { final byte[] resolvedAddress = Inet4Address.getByName(resolvedHost).getAddress(); return new Socket(InetAddress.getByAddress(hostName, resolvedAddress), port, localAddress, localPort); } } return defaultFactory.createSocket(address, port, localAddress, localPort); }