Note: doesn't return the last incomplete line read on EOF, since
it doesn't typically matter anyway
Returns NULL on EOF
int i = 0;
try {
for (;;) {
int result;
result = mInStream.read();
if (result < 0) {
return null;
}
if (ctrlZ && result == 0x1a) {
break;
} else if (result == '\r" || result == '\n") {
if (i == 0) {
// Skip leading cr/lf
continue;
} else {
break;
}
}
mBuffer[i++] = (byte)result;
}
} catch (IOException ex) {
return null;
} catch (IndexOutOfBoundsException ex) {
System.err.println("ATChannel: buffer overflow");
}
try {
return new String(mBuffer, 0, i, "US-ASCII");
} catch (UnsupportedEncodingException ex) {
System.err.println("ATChannel: implausable UnsupportedEncodingException");
return null;
}