question: synchronized void printBuffer ( ) throws IOException { int len = sb . length ( ) ; if ( len > 0 ) { char [ ] chars = new char [ len ] ; sb . getChars ( 0 , len , chars , 0 ) ; sb . setLength ( 0 ) ; super . write ( chars , 0 , chars . length ) ; } }
target:  prints the characters from the buffer and resets it TODO: make sure that printBuffer() is called at the end of the stream in case we have some characters there! (flush() ?)