class Uploader {

  public static void main(String[] args)
      throws IOException, GeneralSecurityException, InterruptedException {
    String jsonFile = System.getProperty("payload");
    checkNotNull(jsonFile, "Missing input json file for the requests");
    checkNotNull(System.getProperty(SERVICE_ACCOUNT_KEY_FILE_CONFIG),
        "Missing " + SERVICE_ACCOUNT_KEY_FILE_CONFIG);

    //resolve the relative path of json file
    Path userDir = Paths.get(System.getProperty("user.dir"));
    Path jsonFilePath = userDir.resolve(jsonFile);
    Path serviceAccountKeyFilePath = userDir
        .resolve(System.getProperty(SERVICE_ACCOUNT_KEY_FILE_CONFIG));

    int requestTimeout = DEFAULT_REQUEST_TIMEOUT_SECONDS;
    if (!Strings.isNullOrEmpty(System.getProperty("contentUpload.requestTimeout"))) {
      requestTimeout = Integer.parseInt(System.getProperty("contentUpload.requestTimeout"));
    }

    boolean enableDebugging = Boolean.getBoolean("contentUpload.enableDebugging");
    String connectorName = Uploader.class.getName();
    if (!Strings.isNullOrEmpty(System.getProperty("contentUpload.connectorName"))) {
      connectorName = System.getProperty("contentUpload.connectorName");
    }

    if (!Files.exists(jsonFilePath)) {
      throw new IOException("payload file " + jsonFilePath.toAbsolutePath() + " does not exists");
    } else if (Files.isDirectory(jsonFilePath)) {
      throw new IOException(
          "payload " + jsonFilePath.toAbsolutePath() + " is a directory. A json file is expected.");
    } else if (!Files.isReadable(jsonFilePath)) {
      throw new IOException("payload " + jsonFilePath.toAbsolutePath() + " is not readable");
    }

    URI jsonUri = jsonFilePath.toUri();
    UploadRequest uploadRequest =
        Uploader.getUploadRequest(
            new InputStreamReader(jsonUri.toURL().openStream(), defaultCharset()));
    checkNotNull(uploadRequest, "upload request is null");

    Uploader uploader =
        new Uploader.Builder()
            .setUploaderHelper(UploaderHelper.getInstance())
            .setRootUrl(System.getProperty("rootUrl", ""))
            .setBaseUri(userDir.toUri())
            .setServiceAccountKeyFilePath(serviceAccountKeyFilePath)
            .setRequestTimeout(requestTimeout, requestTimeout)
            .setEnableDebugging(enableDebugging)
            .setConnectorName(connectorName)
            .build();
    //for each request, use cloudSearch service to upload it
    uploader.execute(uploadRequest);
  }

    Uploader(Builder builder);

}