final protected String getTrimmedString ( ) throws BadMessage { if ( _bufferPosition == 0 ) return "" ; int start = 0 ; boolean quoted = false ; // Look for start while ( start < _bufferPosition ) { final char ch = _internalBuffer [ start ] ; if ( ch == ' ' ) { quoted = true ; break ; } else if ( ch != HttpTokens . SPACE && ch != HttpTokens . TAB ) { break ; } start ++ ; } int end = _bufferPosition ; // Position is of next write // Look for end while ( end > start ) { final char ch = _internalBuffer [ end - 1 ] ; if ( quoted ) { if ( ch == ' ' ) break ; else if ( ch != HttpTokens . SPACE && ch != HttpTokens . TAB ) { throw new BadMessage ( "String might not quoted correctly: '" + getString ( ) + "'" ) ; } } else if ( ch != HttpTokens . SPACE && ch != HttpTokens . TAB ) break ; end -- ; } String str = new String ( _internalBuffer , start , end - start ) ; return str ; }
Returns the string in the buffer minus an leading or trailing whitespace or quotes