public static String getContentTypeAttribute ( String input , String name ) { int begin ; int end ; int index = input . toUpperCase ( ) . indexOf ( name . toUpperCase ( ) ) ; if ( index == - 1 ) { return null ; } index = index + name . length ( ) ; // positioned after the attribute name index = input . indexOf ( ' ' , index ) ; // positioned at the '=' if ( index == - 1 ) { return null ; } index += 1 ; // positioned after the '=' input = input . substring ( index ) . trim ( ) ; if ( input . charAt ( 0 ) == ' ' ) { // attribute value is a quoted string begin = 1 ; end = input . indexOf ( ' ' , begin ) ; if ( end == - 1 ) { return null ; } } else { begin = 0 ; end = input . indexOf ( ' ' ) ; if ( end == - 1 ) { end = input . indexOf ( ' ' ) ; } if ( end == - 1 ) { end = input . length ( ) ; } } return input . substring ( begin , end ) . trim ( ) ; }
Get the value associated with a content - type attribute . Syntax defined in RFC 2045 section 5 . 1 .