Package rife.tools

Class DirBuilder

java.lang.Object
rife.tools.DirBuilder

public class DirBuilder extends Object
Directory and file structure builder, using a fluent API and lambdas to convey the hierarchical structure of on the filesystem in code.
Since:
1.5.19
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs a new DirBuilder instance with the specified directory.
    DirBuilder(File dir, DirAction action)
    Constructs a new DirBuilder instance with the specified path and executes an action on it.
    Constructs a new DirBuilder instance with the specified path.
    DirBuilder(Path path, DirAction action)
    Constructs a new DirBuilder instance with the specified directory and executes an action on it.
  • Method Summary

    Modifier and Type
    Method
    Description
    Deletes the directory represented by this DirBuilder and all of its contents.
    dir(String dir)
    Creates a new subdirectory with the specified name under the directory represented by this DirBuilder.
    dir(String dir, DirAction action)
    Creates a new subdirectory with the specified name under the directory represented by this DirBuilder and executes the specified action on it.
    file(String file, FileAction action)
    Specify a new file under the directory represented by this DirBuilder and executes the specified action on it.
    perms(int mode)
    Sets the permissions for the directory represented by this DirBuilder using the specified Posix mode.
    Sets the permissions for the directory represented by this DirBuilder using the specified permissions.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • DirBuilder

      public DirBuilder(File dir)
      Constructs a new DirBuilder instance with the specified directory.
      Parameters:
      dir - The directory to use for this DirBuilder.
      Since:
      1.5.19
    • DirBuilder

      public DirBuilder(Path path)
      Constructs a new DirBuilder instance with the specified path.
      Parameters:
      path - The path to use for this DirBuilder.
      Since:
      1.5.19
    • DirBuilder

      public DirBuilder(File dir, DirAction action) throws IOException
      Constructs a new DirBuilder instance with the specified path and executes an action on it.
      Parameters:
      dir - The directory to use for this DirBuilder.
      action - The action to execute on the directory.
      Throws:
      IOException - if an error occurs while executing the action.
      Since:
      1.5.19
    • DirBuilder

      public DirBuilder(Path path, DirAction action) throws IOException
      Constructs a new DirBuilder instance with the specified directory and executes an action on it.
      Parameters:
      path - The path to use for this DirBuilder.
      action - The action to execute on the directory.
      Throws:
      IOException - if an error occurs while executing the action.
      Since:
      1.5.19
  • Method Details

    • dir

      public DirBuilder dir(String dir) throws IOException
      Creates a new subdirectory with the specified name under the directory represented by this DirBuilder.
      Parameters:
      dir - The name of the subdirectory to create.
      Returns:
      this DirBuilder instance.
      Throws:
      IOException - if an error occurs while creating the subdirectory.
      Since:
      1.5.19
    • dir

      public DirBuilder dir(String dir, DirAction action) throws IOException
      Creates a new subdirectory with the specified name under the directory represented by this DirBuilder and executes the specified action on it.
      Parameters:
      dir - The name of the subdirectory to create.
      action - The action to execute on the subdirectory.
      Returns:
      this DirBuilder instance.
      Throws:
      IOException - if an error occurs while creating the subdirectory or executing the action.
      Since:
      1.5.19
    • file

      public DirBuilder file(String file, FileAction action) throws IOException
      Specify a new file under the directory represented by this DirBuilder and executes the specified action on it.
      Parameters:
      file - The name of the file to create.
      action - The action to execute on the file.
      Returns:
      this DirBuilder instance.
      Throws:
      IOException - if an error occurs while creating the file or executing the action.
      Since:
      1.5.19
    • delete

      public DirBuilder delete() throws IOException
      Deletes the directory represented by this DirBuilder and all of its contents.
      Returns:
      this DirBuilder instance.
      Throws:
      IOException - if an error occurs while deleting the directory.
      Since:
      1.5.19
    • perms

      public DirBuilder perms(int mode) throws IOException
      Sets the permissions for the directory represented by this DirBuilder using the specified Posix mode.
      Parameters:
      mode - The mode to use for setting the permissions.
      Returns:
      this DirBuilder instance.
      Throws:
      IOException - if an error occurs while setting the permissions.
      Since:
      1.5.19
    • perms

      public DirBuilder perms(Set<PosixFilePermission> permissions) throws IOException
      Sets the permissions for the directory represented by this DirBuilder using the specified permissions.
      Parameters:
      permissions - The permissions to use for setting the permissions.
      Returns:
      this DirBuilder instance.
      Throws:
      IOException - if an error occurs while setting the permissions.
      Since:
      1.5.19