private static List < CharSequence > splitHeader ( CharSequence header ) { final StringBuilder builder = new StringBuilder ( header . length ( ) ) ; final List < CharSequence > protocols = new ArrayList < CharSequence > ( 4 ) ; for ( int i = 0 ; i < header . length ( ) ; ++ i ) { char c = header . charAt ( i ) ; if ( Character . isWhitespace ( c ) ) { // Don't include any whitespace. continue ; } if ( c == ' ' ) { // Add the string and reset the builder for the next protocol. protocols . add ( builder . toString ( ) ) ; builder . setLength ( 0 ) ; } else { builder . append ( c ) ; } } // Add the last protocol if ( builder . length ( ) > 0 ) { protocols . add ( builder . toString ( ) ) ; } return protocols ; }
Splits a comma - separated header value . The returned set is case - insensitive and contains each part with whitespace removed .