I'm reading HTTP request from socket input stream
StringBuilder request = new StringBuilder();
String inputLine;
while (!(inputLine = in.readLine()).equals("")) {
request.append(inputLine + "\r\n");
}
It's working but findbugs
gives the following bug: Dereference of the result of readLine() without nullcheck
. Request ends with ""
not eof
. So how can I check null value here?
Like that:
while ((inputLine = in.readLine()) != null) {
But I assume that you don't want a blank string, use apache commons:
while(StringUtils.isNotBlank(inputLine = in.readLine())) {
Edit:
Also +1 for sodium's comment. However in my opinion this:
("").equals(in.readLine())
is a bit unreadable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With