I would not rely on readLine
for your main loop, because readLine
relies on "future" data (CR, or LF, or CR + LF, and returns null if the end of the stream is reached). Because of this, if CR is not followed by LF, the BufferedReader
gets stuck. This readLine
method is more suitable for reading the contents of a file.
In your case, I will read one character at a time with
while ((myChar = input.read()) != -1) { // processing here, storing information in a buffer and taking appropriate actions if // A CR or LF is found }
But even this behavior is doubtful, because the Unicode char can be more than one byte, so the stream can get stuck if the first byte is sent, and not the second. Are you sure your message is Unicode? If not, an InputStream
would be more appropriate than a Reader
.
source share