Package rife.tools

Class FileBuilder

java.lang.Object
rife.tools.FileBuilder

public class FileBuilder 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 Details

    • FileBuilder

      public FileBuilder(File file)
      Constructs a new FileBuilder object with the specified file.
      Parameters:
      file - The file object to perform operations on
      Since:
      1.5.19
    • FileBuilder

      public FileBuilder(Path path)
      Constructs a new FileBuilder object with the specified path.
      Parameters:
      path - The path to perform operations on
      Since:
      1.5.19
    • FileBuilder

      public FileBuilder(File file, FileAction action) throws IOException
      Constructs a new FileBuilder object with the specified file and performs an action on it.
      Parameters:
      file - The file object to perform operations on
      action - The action to be performed on the file object
      Throws:
      IOException - if an error occurs while executing the action.
      Since:
      1.5.19
    • FileBuilder

      public FileBuilder(Path path, FileAction action) throws IOException
      Constructs a new FileBuilder object with the specified path and performs an action on it.
      Parameters:
      path - The path to perform operations on
      action - The action to be performed on the file object
      Throws:
      IOException - if an error occurs while executing the action.
      Since:
      1.5.19
  • Method Details

    • copy

      public FileBuilder copy(Path source) throws IOException
      Copies the specified source file to the file of this FileBuilder.
      Parameters:
      source - The source file to be copied
      Returns:
      this FileBuilder object
      Throws:
      IOException - if an error occurs while copying the file.
      Since:
      1.5.19
    • move

      public FileBuilder move(Path source) throws IOException
      Moves the specified source file to the file of this FileBuilder.
      Parameters:
      source - The source file to be moved
      Returns:
      this FileBuilder object
      Throws:
      IOException - if an error occurs while moving the file.
      Since:
      1.5.19
    • write

      public FileBuilder write(String text) throws IOException
      Writes the specified text to the file of this FileBuilder.
      Parameters:
      text - The text to be written to the file
      Returns:
      this FileBuilder object
      Throws:
      IOException - if an error occurs while moving the file.
      Since:
      1.5.19
    • touch

      public FileBuilder touch() throws IOException
      Touches the file of this FileBuilder.

      If the file does not exist, it creates a new file. If the file exists, it updates the last access and last modification time of the file.

      Returns:
      this FileBuilder object
      Throws:
      IOException - if an error occurs while touching the file.
      Since:
      1.5.19
    • delete

      public FileBuilder delete() throws IOException
      Deletes the file object of this FileBuilder.
      Returns:
      this FileBuilder object
      Throws:
      IOException - if an error occurs while touching the file.
      Since:
      1.5.19
    • perms

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

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