code: public static String sanitizePath(String path, String substitute) {
      Preconditions.checkArgument(substitute.replaceAll(HDFS_ILLEGAL_TOKEN_REGEX, "").equals(substitute),
          "substitute contains illegal characters: " + substitute);
  
      return path.replaceAll(HDFS_ILLEGAL_TOKEN_REGEX, substitute);
    }
docs: Remove illegal HDFS path characters from the given path. Illegal characters will be replaced
  with the given substitute.