code: public static File copy(InputStream stream, String encoding) throws IOException
    {
      File file = createTempFile();
      copy(new InputStreamReader(stream, encoding), new OutputStreamWriter(new FileOutputStream(file), encoding));
      return file;
    }
docs: Copy text from byte stream using specified encoding to temporary file then close both input stream and temporary
  file. Be aware that temporary file is removed at JVM exit.
  
  @param stream input stream to read from,
  @param encoding used character encoding.
  @return temporarily created file.
  @throws IOException if copy operation fails.