code: public static long readFullyToFile(InputStream is, File toFile)
              throws IOException {
          OutputStream os = org.apache.commons.io.FileUtils.openOutputStream(toFile); 
          try {
              return IOUtils.copyLarge(is, os);
          } finally {
              IOUtils.closeQuietly(os); 
              IOUtils.closeQuietly(is);
          }
      }
docs: Read the entire stream to EOF into the passed file.
  Closes <code>is</code> when done or if an exception.
  @param is Stream to read.
  @param toFile File to write to.
  @throws IOException