Change end-of-stream check to allow whitespace