public void write ( String str , int off , int len ) throws IOException { // Get just the portion of the input string to display String inputString = str . substring ( off , off + len ) ; StringBuffer outputString = new StringBuffer ( ) ; // Build a string tokenizer that uses '\n' as its splitting character // Cycle through all tokens for ( StringTokenizer tokenizer = new StringTokenizer ( inputString , "\n" , true ) ; tokenizer . hasMoreTokens ( ) ; ) { // Replace '\n' token with a <br> String nextToken = tokenizer . nextToken ( ) ; if ( "\n" . equals ( nextToken ) ) { outputString . append ( "<br>" ) ; } else { outputString . append ( nextToken ) ; } } // Write out the generated string out . write ( outputString . toString ( ) ) ; }
Writes a string of characters to the filtered writer . Any newline characters \ n are replaced with an HTML break tag &lt ; br&gt ; .