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 = inStream.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;
}
}
buffer[i++] = (byte)result;
}
} catch (IOException ex) {
return null;
} catch (IndexOutOfBoundsException ex) {
System.err.println("ATChannel: buffer overflow");
}
try {
return new String(buffer, 0, i, "US-ASCII");
} catch (UnsupportedEncodingException ex) {
System.err.println("ATChannel: implausable UnsupportedEncodingException");
return null;
}