java - How can I print each line from a Reader -


so working on project making smtp server. trying read in each line of input , hand line thread processing. however, code, lines aren't sent until connection ended. think has fact new line doesn't break while loop:

while (true) {         stringbuilder line = new stringbuilder();         try {             int c;             while ((c = in.read()) != -1){ //this reads line                 line.append((char) c); //add character our line             }             string response = parser.parse(line.tostring); //give line read parser processing         } catch (ioexception ex) {             system.err.println("ioexception while reading clients mesasge");         } } 

i going quote "java network programming 4th edition" elliot harold because author says shouldn't use readline() method of bufferedreader or datainputstream because different operating systems have different newline delimeters (\n or \r\n or else)

also, i'm not using either of streams if wanted use readline() wouldn't able do.

anyone have idea how can accomplish i'm trying do

while ((c = in.read()) != -1){ //this reads line 

no doesn't. reads 1 character.

use bufferedreader.readline().

i going quote "java network programming 4th edition" elliot harold because author says shouldn't use readline() method of bufferedreader or datainputstream because different operating systems have different newline delimeters (\n or \r\n or else).

elliot rusty harold needs read javadoc, , you. grade bs. see reviews @ amazon long list of mistakes in book.


Comments