Almost, the line variable is null so you can't invoke .equals without causing an NPE. You could choose to initialise the string to something other than the termination condition. Another way to go is to reverse the equality operands since equals() can correctly cope with null as a parameter, e.g.Hope this works
while(!"-END_OF_STREAM-".equals(line))