private Optional < String [ ] > parseProxy ( String url , String defPort ) { if ( ! Strings . isNullOrEmpty ( url ) ) { String [ ] result = new String [ 2 ] ; int p = url . indexOf ( "://" ) ; if ( p != - 1 ) url = url . substring ( p + 3 ) ; if ( ( p = url . indexOf ( ' ' ) ) != - 1 ) url = url . substring ( p + 1 ) ; if ( ( p = url . indexOf ( ' ' ) ) != - 1 ) { result [ 0 ] = url . substring ( 0 , p ) ; result [ 1 ] = url . substring ( p + 1 ) ; } else { result [ 0 ] = url ; result [ 1 ] = defPort ; } // remove trailing slash from the host name p = result [ 0 ] . indexOf ( ' ' ) ; if ( p != - 1 ) { result [ 0 ] = result [ 0 ] . substring ( 0 , p ) ; } // remove trailing slash from the port number p = result [ 1 ] . indexOf ( ' ' ) ; if ( p != - 1 ) { result [ 1 ] = result [ 1 ] . substring ( 0 , p ) ; } return Optional . of ( result ) ; } return Optional . empty ( ) ; }
Given a proxy URL returns a two element arrays containing the host name and the port