public static void decode88591To(InputStream in, MultiMap<String> map, int maxLength, int maxKeys)
            throws IOException {
        synchronized (map) {
            StringBuffer buffer = new StringBuffer();
            String key = null;
            String value = null;

            int b;

            int totalLength = 0;
            while ((b = in.read()) >= 0) {
                switch ((char) b) {
                    case '&':
                        value = buffer.length() == 0 ? "" : buffer.toString();
                        buffer.setLength(0);
                        if (key != null) {
                            map.add(key, value);
                        } else if (value != null && value.length() > 0) {
                            map.add(value, "");
                        }
                        key = null;
                        value = null;
                        if (maxKeys > 0 && map.size() > maxKeys)
                            throw new IllegalStateException(String.format("Form with too many keys [%d > %d]", map.size(), maxKeys));
                        break;

                    case '=':
                        if (key != null) {
                            buffer.append((char) b);
                            break;
                        }
                        key = buffer.toString();
                        buffer.setLength(0);
                        break;

                    case '+':
                        buffer.append(' ');
                        break;

                    case '%':
                        int code0 = in.read();
                        int code1 = in.read();
                        buffer.append(decodeHexChar(code0, code1));
                        break;

                    default:
                        buffer.append((char) b);
                        break;
                }
                if (maxLength >= 0 && (++totalLength > maxLength))
                    throw new IllegalStateException(String.format("Form with too many keys [%d > %d]", map.size(), maxKeys));
            }

            if (key != null) {
                value = buffer.length() == 0 ? "" : buffer.toString();
                buffer.setLength(0);
                map.add(key, value);
            } else if (buffer.length() > 0) {
                map.add(buffer.toString(), "");
            }
        }
    }
public static void decode88591To ( InputStream in , MultiMap < String > map , int maxLength , int maxKeys ) throws IOException { synchronized ( map ) { StringBuffer buffer = new StringBuffer ( ) ; String key = null ; String value = null ; int b ; int totalLength = 0 ; while ( ( b = in . read ( ) ) >= 0 ) { switch ( ( char ) b ) { case '&' : value = buffer . length ( ) == 0 ? "" : buffer . toString ( ) ; buffer . setLength ( 0 ) ; if ( key != null ) { map . add ( key , value ) ; } else if ( value != null && value . length ( ) > 0 ) { map . add ( value , "" ) ; } key = null ; value = null ; if ( maxKeys > 0 && map . size ( ) > maxKeys ) throw new IllegalStateException ( String . format ( "Form with too many keys [%d > %d]" , map . size ( ) , maxKeys ) ) ; break ; case '=' : if ( key != null ) { buffer . append ( ( char ) b ) ; break ; } key = buffer . toString ( ) ; buffer . setLength ( 0 ) ; break ; case '+' : buffer . append ( ' ' ) ; break ; case '%' : int code0 = in . read ( ) ; int code1 = in . read ( ) ; buffer . append ( decodeHexChar ( code0 , code1 ) ) ; break ; default : buffer . append ( ( char ) b ) ; break ; } if ( maxLength >= 0 && ( ++ totalLength > maxLength ) ) throw new IllegalStateException ( String . format ( "Form with too many keys [%d > %d]" , map . size ( ) , maxKeys ) ) ; } if ( key != null ) { value = buffer . length ( ) == 0 ? "" : buffer . toString ( ) ; buffer . setLength ( 0 ) ; map . add ( key , value ) ; } else if ( buffer . length ( ) > 0 ) { map . add ( buffer . toString ( ) , "" ) ; } } }
Decoded parameters to MultiMap, using ISO8859-1 encodings.

@param in        InputSteam to read
@param map       MultiMap to add parameters to
@param maxLength maximum length of form to read
@param maxKeys   maximum number of keys to read or -1 for no limit
@throws IOException if unable to decode inputstream as ISO8859-1