Class FileManager

java.lang.Object
io.github.monsieurdoceo.filizer.storage.api.FileManager

public final class FileManager extends Object
Provides access to managed files.

This class is responsible for creating, registering, retrieving, synchronizing, and deleting CustomFile instances.

  • Constructor Details

  • Method Details

    • containsFile

      public boolean containsFile(String name)
      Checks whether a file with the given name exists in storage.
      Parameters:
      name - the file name to search for
      Returns:
      true if the file exists, false otherwise
    • findFile

      public Optional<CustomFile> findFile(String name)
      Attempts to retrieve a registered file by its name.
      Parameters:
      name - the file name
      Returns:
      the matching file, if present
    • findFile

      public Optional<CustomFile> findFile(Path path, String name)
      Attempts to retrieve a registered file by its path.
      Parameters:
      path - the parent directory path
      name - the file name
      Returns:
      the matching file, if present
    • requireFile

      public CustomFile requireFile(String name)
      Retrieves a registered file.
      Parameters:
      name - the file name
      Returns:
      the matching file
      Throws:
      IllegalArgumentException - if the file does not exist
    • createFile

      public CustomFile createFile(String path, String name)
      Creates a new CustomFile from a parent path and a name.
      Parameters:
      path - the parent directory path
      name - the file name
      Returns:
      the created CustomFile
    • createFile

      public CustomFile createFile(File parent, String name)
      Creates a new CustomFile from a parent directory and file name.

      This method behaves like createFile(String, String) but accepts a File as the parent reference.

      Parameters:
      parent - the parent directory
      name - the file name
      Returns:
      the created CustomFile
    • removeFile

      public void removeFile(String name)
      Removes a CustomFile from storage by this name.
      Parameters:
      name - the file name
    • removeFile

      public void removeFile(Path path, String name)
      Removes a file from storage by its path and name.
      Parameters:
      path - the parent path
      name - the file name
    • removeFile

      public void removeFile(CustomFile customFile)
      Removes the given CustomFile from storage.

      This method behaves like removeFile(String) but operates directly on a CustomFile instance.

      Parameters:
      customFile - the file to remove
    • storeAllFiles

      public void storeAllFiles(Path root) throws IOException
      Recursively stores all regular files found under the given root path.

      If the root path does not exist, it is created automatically.

      Parameters:
      root - the root directory to scan
      Throws:
      IOException - if the directory cannot be created or files cannot be accessed
    • deleteFile

      public boolean deleteFile(String name)
      Deletes the CustomFile associated with the given name.
      Parameters:
      name - file name
      Returns:
      true if the file was deleted successfully, otherwise false
    • deleteFile

      public boolean deleteFile(CustomFile customFile)
      Deletes the given CustomFile from filesystem and removes it from storage.

      This method behaves like deleteFile(String) but operates directly on a CustomFile instance.

      Parameters:
      customFile - the file to delete
      Returns:
      true if the file was deleted successfully, otherwise false
    • getRegistry

      public FileRegistry getRegistry()
      Retrieves the underlying file storage instance.
      Returns:
      the file storage
    • getSynchronizer

      public FileSynchronizer getSynchronizer()
      Retrieves the file synchronization instance.
      Returns:
      the file synchronization instance