private static Map < String , String > parseParameters ( String expression ) { // charset = UTF-8 Map < String , String > parameters = new HashMap <> ( ) ; int parametersSeparatorIndex = 0 ; for ( ; ; ) { int valueSeparatorIndex = expression . indexOf ( ' ' , parametersSeparatorIndex ) ; if ( valueSeparatorIndex == - 1 ) { break ; } String name = expression . substring ( parametersSeparatorIndex , valueSeparatorIndex ) . trim ( ) ; ++ valueSeparatorIndex ; parametersSeparatorIndex = expression . indexOf ( ' ' , valueSeparatorIndex ) ; if ( parametersSeparatorIndex == - 1 ) { parametersSeparatorIndex = expression . length ( ) ; } if ( valueSeparatorIndex == parametersSeparatorIndex ) { throw new SyntaxException ( "Invalid content type parameters |%s|. Value is empty." , expression ) ; } if ( parameters . put ( name , expression . substring ( valueSeparatorIndex , parametersSeparatorIndex ) . trim ( ) ) != null ) { throw new SyntaxException ( "Invalid content type parameters |%s|. Name override |%s|." , expression , name ) ; } ++ parametersSeparatorIndex ; } if ( parameters . isEmpty ( ) ) { throw new SyntaxException ( "Invalid content type parameters |%s|. Missing name/value separator." , expression ) ; } return parameters ; }
Parse content type parameters . Given parameters expression should be valid accordingly grammar from class description ; it should not start with parameters separator that is semicolon .