You are adding a newline after every read. Is there anythign in your incoming data that would indicate when one line is done and the next one begins? If so you can check for this and add the newline in the correct place. As is in any given read you could get part of a line and a newline character would be added to it via your code breaking the line apart. I do not know enough about your incoming data stream to tell you how would be best to handle it.