/**
   * Deletes file or directory. If directory is not empty, it's deleted recursively.
   *
   * @param fs IGFS.
   * @param path File or directory path.
   * @throws IgniteException In case of error.
   */
  private static void delete(IgniteFileSystem fs, IgfsPath path) throws IgniteException {
    assert fs != null;
    assert path != null;

    if (fs.exists(path)) {
      boolean isFile = fs.info(path).isFile();

      try {
        fs.delete(path, true);

        System.out.println();
        System.out.println(">>> Deleted " + (isFile ? "file" : "directory") + ": " + path);
      } catch (IgfsException e) {
        System.out.println();
        System.out.println(
            ">>> Failed to delete "
                + (isFile ? "file" : "directory")
                + " [path="
                + path
                + ", msg="
                + e.getMessage()
                + ']');
      }
    } else {
      System.out.println();
      System.out.println(">>> Won't delete file or directory (doesn't exist): " + path);
    }
  }
  /**
   * Opens file and reads it to byte array.
   *
   * @param fs IgniteFs.
   * @param path File path.
   * @throws IgniteException If file can't be opened.
   * @throws IOException If data can't be read.
   */
  private static void read(IgniteFileSystem fs, IgfsPath path) throws IgniteException, IOException {
    assert fs != null;
    assert path != null;
    assert fs.info(path).isFile();

    byte[] data = new byte[(int) fs.info(path).length()];

    try (IgfsInputStream in = fs.open(path)) {
      in.read(data);
    }

    System.out.println();
    System.out.println(">>> Read data from " + path + ": " + Arrays.toString(data));
  }
  /**
   * Opens file and appends provided data to it.
   *
   * @param fs IGFS.
   * @param path File path.
   * @param data Data.
   * @throws IgniteException If file can't be created.
   * @throws IOException If data can't be written.
   */
  private static void append(IgniteFileSystem fs, IgfsPath path, byte[] data)
      throws IgniteException, IOException {
    assert fs != null;
    assert path != null;
    assert data != null;
    assert fs.info(path).isFile();

    try (OutputStream out = fs.append(path, true)) {
      System.out.println();
      System.out.println(">>> Opened file: " + path);

      out.write(data);
    }

    System.out.println();
    System.out.println(">>> Appended data to file: " + path);
  }
  /**
   * Lists files in directory.
   *
   * @param fs IGFS.
   * @param path Directory path.
   * @throws IgniteException In case of error.
   */
  private static void list(IgniteFileSystem fs, IgfsPath path) throws IgniteException {
    assert fs != null;
    assert path != null;
    assert fs.info(path).isDirectory();

    Collection<IgfsPath> files = fs.listPaths(path);

    if (files.isEmpty()) {
      System.out.println();
      System.out.println(">>> No files in directory: " + path);
    } else {
      System.out.println();
      System.out.println(">>> List of files in directory: " + path);

      for (IgfsPath f : files) System.out.println(">>>     " + f.name());
    }

    System.out.println();
  }
  /**
   * Creates directories.
   *
   * @param fs IGFS.
   * @param path Directory path.
   * @throws IgniteException In case of error.
   */
  private static void mkdirs(IgniteFileSystem fs, IgfsPath path) throws IgniteException {
    assert fs != null;
    assert path != null;

    try {
      fs.mkdirs(path);

      System.out.println();
      System.out.println(">>> Created directory: " + path);
    } catch (IgfsException e) {
      System.out.println();
      System.out.println(
          ">>> Failed to create a directory [path=" + path + ", msg=" + e.getMessage() + ']');
    }

    System.out.println();
  }
  /**
   * Creates file and writes provided data to it.
   *
   * @param fs IGFS.
   * @param path File path.
   * @param data Data.
   * @throws IgniteException If file can't be created.
   * @throws IOException If data can't be written.
   */
  private static void create(IgniteFileSystem fs, IgfsPath path, @Nullable byte[] data)
      throws IgniteException, IOException {
    assert fs != null;
    assert path != null;

    try (OutputStream out = fs.create(path, true)) {
      System.out.println();
      System.out.println(">>> Created file: " + path);

      if (data != null) {
        out.write(data);

        System.out.println();
        System.out.println(">>> Wrote data to file: " + path);
      }
    }

    System.out.println();
  }
 /**
  * Prints information for file or directory.
  *
  * @param fs IGFS.
  * @param path File or directory path.
  * @throws IgniteException In case of error.
  */
 private static void printInfo(IgniteFileSystem fs, IgfsPath path) throws IgniteException {
   System.out.println();
   System.out.println("Information for " + path + ": " + fs.info(path));
 }