private Map < String , String [ ] > parseQueryString ( String data ) { Map < String , String [ ] > map = new Hashtable < String , String [ ] > ( ) ; if ( null == data ) { return map ; } String valArray [ ] = null ; char [ ] chars = data . toCharArray ( ) ; int key_start = 0 ; for ( int i = 0 ; i < chars . length ; i ++ ) { // look for the key name delimiter if ( ' ' == chars [ i ] ) { if ( i == key_start ) { // missing the key name throw new IllegalArgumentException ( "Missing key name: " + i ) ; } String key = parseName ( chars , key_start , i ) ; int value_start = ++ i ; for ( ; i < chars . length && ' ' != chars [ i ] ; i ++ ) { // just keep looping looking for the end or & } if ( i > value_start ) { // did find at least one char for the value String value = parseName ( chars , value_start , i ) ; if ( map . containsKey ( key ) ) { String oldVals [ ] = map . get ( key ) ; valArray = new String [ oldVals . length + 1 ] ; System . arraycopy ( oldVals , 0 , valArray , 0 , oldVals . length ) ; valArray [ oldVals . length ] = value ; } else { valArray = new String [ ] { value } ; } map . put ( key , valArray ) ; } key_start = i + 1 ; } } return map ; }
Parse a string of query parameters into a Map representing the values stored using the name as the key .