Use a buffered input stream and read the contents in from the inputstream in chunks.
Meanwhile using a buffered output stream write out the chunks to your file.
I don't know why you are trying to cast to FileInputStream. Don't do that. Just use the input stream (wrap it with a buffered stream).