private static Map < String , String > parseQuery ( URL url ) throws UnsupportedEncodingException { Map < String , String > params = new LinkedHashMap < String , String > ( ) ; String query = url . getQuery ( ) ; if ( query == null || query . isEmpty ( ) ) { // empty query return params ; } String [ ] pairs = url . getQuery ( ) . split ( "&" ) ; for ( String pair : pairs ) { int i = pair . indexOf ( "=" ) ; String key = pair ; if ( i > 0 ) { key = URLDecoder . decode ( pair . substring ( 0 , i ) , "UTF-8" ) ; } String value = null ; if ( i > 0 && pair . length ( ) > i + 1 ) { value = URLDecoder . decode ( pair . substring ( i + 1 ) , "UTF-8" ) ; } // note that this uses the last instance if a parameter is specified multiple times params . put ( key . toLowerCase ( ) , value ) ; } return params ; }
Parses URL parameters into a map . Keys are stored lower - case .