code: public static File copyIntoTempFile(String fileName, InputStream inputStream)
        throws IOException {
      BufferedInputStream bufferedStream = inputStream instanceof BufferedInputStream ? (BufferedInputStream) inputStream
          : new BufferedInputStream(inputStream);
      File destFile = null;
      try {
        destFile = File.createTempFile(fileName, null);
        destFile.deleteOnExit();
  
        FileOutputStream fileOutputStream = new FileOutputStream(destFile);
        BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(fileOutputStream);
        try {
          byte[] buffer = new byte[8192];
          int length;
          while ((length = bufferedStream.read(buffer)) > 0) {
            bufferedOutputStream.write(buffer, 0, length);
          }
        } finally {
          bufferedOutputStream.close();
          fileOutputStream.close();
        }
      } finally {
        bufferedStream.close();
        inputStream.close();
      }
      return destFile;
    }
docs: Copies <code>inputStream</code> into a temporary file <code>fileName</code>.
  
  @param fileName file name
  @param inputStream stream to copy from
  @return temporary file
  @throws IOException if an IO error occurs