[Issue #1483] Break out of loop if output stream does not have space to write bytes