protected Map < String , String > getHeadersMap ( String headerPart ) { final int len = headerPart . length ( ) ; final Map < String , String > headers = new HashMap < String , String > ( ) ; int start = 0 ; for ( ; ; ) { int end = parseEndOfLine ( headerPart , start ) ; if ( start == end ) { break ; } String header = headerPart . substring ( start , end ) ; start = end + 2 ; while ( start < len ) { int nonWs = start ; while ( nonWs < len ) { char c = headerPart . charAt ( nonWs ) ; if ( c != ' ' && c != ' ' ) { break ; } ++ nonWs ; } if ( nonWs == start ) { break ; } // continuation line found end = parseEndOfLine ( headerPart , nonWs ) ; header += " " + headerPart . substring ( nonWs , end ) ; start = end + 2 ; } // parse header line final int colonOffset = header . indexOf ( ' ' ) ; if ( colonOffset == - 1 ) { // this header line is malformed, skip it. continue ; } String headerName = header . substring ( 0 , colonOffset ) . trim ( ) ; String headerValue = header . substring ( header . indexOf ( ' ' ) + 1 ) . trim ( ) ; if ( headers . containsKey ( headerName ) ) { headers . put ( headerName , headers . get ( headerName ) + "," + headerValue ) ; } else { headers . put ( headerName , headerValue ) ; } } return headers ; }
Retreives a map with the headers of a part .