Add null check for InputStream