public static String formatPossibleIpv6Address(String address) { if(address == null) { return null; } String ipv6Address; if (address.startsWith("[") && address.endsWith("]")) { ipv6Address = address.substring(0, address.lastIndexOf(']')).substring(1); } else { ipv6Address = address; } // Definitely not an IPv6, return untouched input. if (!mayBeIPv6Address(ipv6Address)) { return ipv6Address; } return '[' + canonize(ipv6Address) + ']'; }
private static boolean checkForWindows() { return checkForPresence("os.name", "win"); }
/** * Formats input address. For IPV4 returns simply host address, for IPV6 formats address according to <a * href="http://tools.ietf.org/html/rfc5952">RFC5952</a> rules. It does not embed IPV6 address in '[', ']', since those are part of IPV6 URI literal. * * @param inet * @return */ public static String formatAddress(InetAddress inet){ if(inet == null){ throw new IllegalArgumentException(); } if(inet instanceof Inet4Address){ return inet.getHostAddress(); } else if (inet instanceof Inet6Address){ byte[] byteRepresentation = inet.getAddress(); int[] hexRepresentation = new int[IPV6_LEN]; for(int i=0;i < hexRepresentation.length;i++){ hexRepresentation[i] = ( byteRepresentation[2*i] & 0xFF) << 8 | ( byteRepresentation[2*i+1] & 0xFF ); } compactLongestZeroSequence(hexRepresentation); return formatAddress6(hexRepresentation); } else { return inet.getHostAddress(); } }
/** * Converts socket address into string literal, which has form: 'address:port'. Example:<br> * <ul> * <li>127.0.0.1:8080</li> * <li>dns.name.com:8080</li> * <li>[0fe:1::20]:8080</li> * <li>[::1]:8080</li> * </ul> * @param inet * @return */ public static String formatAddress(InetSocketAddress inet){ if(inet == null){ throw new NullPointerException(); } StringBuilder result = new StringBuilder(); if(inet.isUnresolved()){ result.append(inet.getHostName()); }else{ result.append(formatPossibleIpv6Address(formatAddress(inet.getAddress()))); } result.append(":").append(inet.getPort()); return result.toString(); }
if (!mayBeIPv6Address(ipv6Address)) { return ipv6Address; if (isIPv4AddressInIPv6(ipv6Address)) {
/** * Formats input address. For IPV4 returns simply host address, for IPV6 formats address according to <a * href="http://tools.ietf.org/html/rfc5952">RFC5952</a> rules. It embeds IPV6 address in '[', ']'. * * @param inet * @return */ public static String formatIPAddressForURI(InetAddress inet){ if(inet == null){ throw new IllegalArgumentException(); } if(inet instanceof Inet4Address){ return inet.getHostAddress(); } else if (inet instanceof Inet6Address){ return '[' + formatAddress(inet) + ']'; } else { return inet.getHostAddress(); } }
final String connUserName = getEnvString(environment, connectionPrefix + EJB_USERNAME_KEY, null, true); final String rawHostString = getEnvString(environment, connectionPrefix + EJB_HOST_KEY, null, true); final String connHostName = NetworkUtils.formatPossibleIpv6Address(rawHostString); final String connPassword = getEnvString(environment, connectionPrefix + EJB_PASSWORD_KEY, null, true); final String connPasswordBase64 = getEnvString(environment, connectionPrefix + EJB_PASSWORD_BASE64_KEY, null, true);
/** * Converts socket address into string literal, which has form: 'address:port'. Example:<br> * <ul> * <li>127.0.0.1:8080</li> * <li>dns.name.com:8080</li> * <li>[0fe:1::20]:8080</li> * <li>[::1]:8080</li> * </ul> * @param inet * @return */ public static String formatAddress(InetSocketAddress inet){ if(inet == null){ throw new NullPointerException(); } StringBuilder result = new StringBuilder(); if(inet.isUnresolved()){ result.append(inet.getHostName()); }else{ result.append(formatPossibleIpv6Address(formatAddress(inet.getAddress()))); } result.append(":").append(inet.getPort()); return result.toString(); }
if (!mayBeIPv6Address(ipv6Address)) { return ipv6Address; if (isIPv4AddressInIPv6(ipv6Address)) {
/** * Formats input address. For IPV4 returns simply host address, for IPV6 formats address according to <a * href="http://tools.ietf.org/html/rfc5952">RFC5952</a> rules. It embeds IPV6 address in '[', ']'. * * @param inet * @return */ public static String formatIPAddressForURI(InetAddress inet){ if(inet == null){ throw new IllegalArgumentException(); } if(inet instanceof Inet4Address){ return inet.getHostAddress(); } else if (inet instanceof Inet6Address){ return '[' + formatAddress(inet) + ']'; } else { return inet.getHostAddress(); } }
final String connUserName = getEnvString(environment, connectionPrefix + EJB_USERNAME_KEY, null, true); final String rawHostString = getEnvString(environment, connectionPrefix + EJB_HOST_KEY, null, true); final String connHostName = NetworkUtils.formatPossibleIpv6Address(rawHostString); final String connPassword = getEnvString(environment, connectionPrefix + EJB_PASSWORD_KEY, null, true); final String connPasswordBase64 = getEnvString(environment, connectionPrefix + EJB_PASSWORD_BASE64_KEY, null, true);
private static boolean checkForLinux() { return checkForPresence("os.name", "linux"); }
public static String formatPossibleIpv6Address(String address) { if(address == null) { return null; } String ipv6Address; if (address.startsWith("[") && address.endsWith("]")) { ipv6Address = address.substring(0, address.lastIndexOf(']')).substring(1); } else { ipv6Address = address; } // Definitely not an IPv6, return untouched input. if (!mayBeIPv6Address(ipv6Address)) { return ipv6Address; } return '[' + canonize(ipv6Address) + ']'; }
/** * Converts socket address into string literal, which has form: 'address:port'. Example:<br> * <ul> * <li>127.0.0.1:8080</li> * <li>dns.name.com:8080</li> * <li>[0fe:1::20]:8080</li> * <li>[::1]:8080</li> * </ul> * @param inet * @return */ public static String formatAddress(InetSocketAddress inet){ if(inet == null){ throw new NullPointerException(); } StringBuilder result = new StringBuilder(); if(inet.isUnresolved()){ result.append(inet.getHostName()); }else{ result.append(formatPossibleIpv6Address(formatAddress(inet.getAddress()))); } result.append(":").append(inet.getPort()); return result.toString(); }
/** * Formats input address. For IPV4 returns simply host address, for IPV6 formats address according to <a * href="http://tools.ietf.org/html/rfc5952">RFC5952</a> rules. It does not embed IPV6 address in '[', ']', since those are part of IPV6 URI literal. * * @param inet * @return */ public static String formatAddress(InetAddress inet){ if(inet == null){ throw new IllegalArgumentException(); } if(inet instanceof Inet4Address){ return inet.getHostAddress(); } else if (inet instanceof Inet6Address){ byte[] byteRepresentation = inet.getAddress(); int[] hexRepresentation = new int[IPV6_LEN]; for(int i=0;i < hexRepresentation.length;i++){ hexRepresentation[i] = ( byteRepresentation[2*i] & 0xFF) << 8 | ( byteRepresentation[2*i+1] & 0xFF ); } compactLongestZeroSequence(hexRepresentation); return formatAddress6(hexRepresentation); } else { return inet.getHostAddress(); } }
if (!mayBeIPv6Address(ipv6Address)) { return ipv6Address; if (isIPv4AddressInIPv6(ipv6Address)) {
/** * Formats input address. For IPV4 returns simply host address, for IPV6 formats address according to <a * href="http://tools.ietf.org/html/rfc5952">RFC5952</a> rules. It embeds IPV6 address in '[', ']'. * * @param inet * @return */ public static String formatIPAddressForURI(InetAddress inet){ if(inet == null){ throw new IllegalArgumentException(); } if(inet instanceof Inet4Address){ return inet.getHostAddress(); } else if (inet instanceof Inet6Address){ return '[' + formatAddress(inet) + ']'; } else { return inet.getHostAddress(); } }
final String connUserName = getEnvString(environment, connectionPrefix + EJB_USERNAME_KEY, null, true); final String rawHostString = getEnvString(environment, connectionPrefix + EJB_HOST_KEY, null, true); final String connHostName = NetworkUtils.formatPossibleIpv6Address(rawHostString); final String connPassword = getEnvString(environment, connectionPrefix + EJB_PASSWORD_KEY, null, true); final String connPasswordBase64 = getEnvString(environment, connectionPrefix + EJB_PASSWORD_BASE64_KEY, null, true);
private static boolean checkForSolaris() { return checkForPresence("os.name", "sun"); }
public static String formatPossibleIpv6Address(String address) { if(address == null) { return null; } String ipv6Address; if (address.startsWith("[") && address.endsWith("]")) { ipv6Address = address.substring(0, address.lastIndexOf(']')).substring(1); } else { ipv6Address = address; } // Definitely not an IPv6, return untouched input. if (!mayBeIPv6Address(ipv6Address)) { return ipv6Address; } return '[' + canonize(ipv6Address) + ']'; }