Class FileService


  • public class FileService
    extends Object
    File prompting and loading service.
    • Constructor Detail

      • FileService

        public FileService()
    • Method Detail

      • promptForLoad

        public static Path promptForLoad​(String title)
        Prompt the user for a file path.
        Parameters:
        title - the prompts title
        Returns:
        the chosen file's path from the prompt
      • promptForSave

        public static Path promptForSave​(String title,
                                         String extension)
        Prompt the user for a file save path.
        Parameters:
        title - the prompts title
        Returns:
        the chosen file's path from the prompt
      • promptForDirectory

        public static Path promptForDirectory​(String title)
        Prompt the user for a directory.
        Parameters:
        title - the prompts title
        Returns:
        the chosen directory's path from the prompt
        See Also:
        promptForLoad(String)
      • write

        public static void write​(Path path,
                                 org.dom4j.Document document)
        Write a xml Document to a file.
        Parameters:
        path - files path
        document - xml document to write
      • write

        public static void write​(Path path,
                                 org.dom4j.Element element)
        Write a xml Element as root element to a file.
        Parameters:
        path - file path
        element - xml element to write
      • read

        public static org.dom4j.Document read​(Path file)
        Read a xml Document from a file.
        Parameters:
        file - the files path
        Returns:
        parsed xml document
      • uniquePath

        public static Path uniquePath​(String name,
                                      String ext)
        Get a distinct file from the file system.
        Parameters:
        name - name prefix to use
        ext - file extension to use
        Returns:
        file handler to a distinct file
      • counter

        public static int counter​(Path path,
                                  String prefix,
                                  String suffix)
        Counts the files matching the pattern prefix-number.suffix
        Parameters:
        path - directory with files to count
        prefix - file name prefix
        suffix - file extension
        Returns:
        amount of files matching the pattern