Adds nullcheck to outputstream