private Path writeExportedRangerPoliciesToJsonFile(String jsonString, String fileName, Path stagingDirPath,
                                                     HiveConf conf)
      throws IOException {
    String filePath = "";
    Path newPath = null;
    FSDataOutputStream outStream = null;
    OutputStreamWriter writer = null;
    try {
      if (!StringUtils.isEmpty(jsonString)) {
        FileSystem fileSystem = stagingDirPath.getFileSystem(conf);
        if (fileSystem != null) {
          if (!fileSystem.exists(stagingDirPath)) {
            fileSystem.mkdirs(stagingDirPath);
          }
          newPath = stagingDirPath.suffix(File.separator + fileName);
          outStream = fileSystem.create(newPath, true);
          writer = new OutputStreamWriter(outStream, "UTF-8");
          writer.write(jsonString);
        }
      }
    } catch (IOException ex) {
      if (newPath != null) {
        filePath = newPath.toString();
      }
      throw new IOException("Failed to write json string to file:" + filePath, ex);
    } catch (Exception ex) {
      if (newPath != null) {
        filePath = newPath.toString();
      }
      throw new IOException("Failed to write json string to file:" + filePath, ex);
    } finally {
      try {
        if (writer != null) {
          writer.close();
        }
        if (outStream != null) {
          outStream.close();
        }
      } catch (Exception ex) {
        throw new IOException("Unable to close writer/outStream.", ex);
      }
    }
    return newPath;
  }
RangerRestClientImpl to connect to Ranger and export policies.
ql/src/java/org/apache/hadoop/hive/ql/exec/repl/ranger/RangerRestClientImpl.java