private boolean isValidEndpoint ( String endpoint ) { if ( InetAddressValidator . getInstance ( ) . isValid ( endpoint ) ) { return true ; } // endpoint may be a hostname // refer https://en.wikipedia.org/wiki/Hostname#Restrictions_on_valid_host_names // why checks are done like below if ( endpoint . length ( ) < 1 || endpoint . length ( ) > 253 ) { return false ; } for ( String label : endpoint . split ( "\\." ) ) { if ( label . length ( ) < 1 || label . length ( ) > 63 ) { return false ; } if ( ! ( label . matches ( "^[a-zA-Z0-9]([a-zA-Z0-9-]*[a-zA-Z0-9])?$" ) ) ) { return false ; } } return true ; }
Returns true if given endpoint is valid else false .