private static String stripHostname ( final String originalHostname ) { // Check if the hostname domains the domain separator character final int index = originalHostname . indexOf ( DOMAIN_SEPARATOR ) ; if ( index == - 1 ) { return originalHostname ; } // Make sure we are not stripping an IPv4 address final Matcher matcher = IPV4_PATTERN . matcher ( originalHostname ) ; if ( matcher . matches ( ) ) { return originalHostname ; } if ( index == 0 ) { throw new IllegalStateException ( "Hostname " + originalHostname + " starts with a " + DOMAIN_SEPARATOR ) ; } return originalHostname . substring ( 0 , index ) ; }
Looks for a domain suffix in a FQDN and strips it if present .