Class FileFactory


  • public final class FileFactory
    extends java.lang.Object
    The class FileFactory helps you to create files or directories
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static boolean mkParentDirs​(java.io.File file)
      Creates the parent directories from the given file.
      static boolean newDirectories​(java.nio.file.Path dir, java.nio.file.attribute.FileAttribute<?>... attrs)
      Creates a new directory from the given Path object and the optional FileAttribute.

      Note: this method decorates the Files.createDirectories(Path, FileAttribute...) and returns if the directory is created or not.
      static FileCreationState newDirectories​(java.util.Collection<java.io.File> directories)
      Creates the directories.
      static boolean newDirectoriesQuietly​(java.nio.file.Path dir, java.nio.file.attribute.FileAttribute<?>... attrs)
      Creates a new directory from the given Path object and the optional FileAttribute.

      Note: this method decorates the Files.createDirectories(Path, FileAttribute...) and returns if the directory is created or not.
      static FileCreationState newDirectory​(java.io.File directory)
      Creates a new directory from the given File object
      static java.io.File newDirectory​(java.io.File parentDirectory, java.lang.String directoryName)
      Factory method for creating the new directory as File objects if it is not exists.
      static java.io.File newDirectory​(java.lang.String absolutePath)
      Factory method that creates a new File object, if the given boolean flag is true a new empty file will be created on the file system
      static java.io.File newDirectory​(java.lang.String parentDirectory, java.lang.String directoryName)
      Factory method for creating the new directory as File objects if it is not exists.
      static boolean newDirectory​(java.nio.file.Path dir, java.nio.file.attribute.FileAttribute<?>... attrs)
      Creates a new directory from the given Path object and the optional FileAttribute.

      Note: this method decorates the Files.createDirectory(Path, FileAttribute...) and returns if the directory is created or not.
      static java.io.File newDirectoryQuietly​(java.lang.String absolutePath)
      Factory method that creates a new File object, if the given boolean flag is true a new empty file will be created on the file system
      static java.io.File newDirectoryQuietly​(java.lang.String parentDirectory, java.lang.String directoryName)
      Factory method for creating the new directory as File objects if it is not exists.
      static boolean newDirectoryQuietly​(java.nio.file.Path dir, java.nio.file.attribute.FileAttribute<?>... attrs)
      Creates a new directory from the given Path object and the optional FileAttribute.

      Note: this method decorates the Files.createDirectory(Path, FileAttribute...) and returns if the directory is created or not.
      static java.io.File newFile​(FileInfo fileInfo)
      Factory method for creating the new File from the given FileInfo object
      static FileCreationState newFile​(java.io.File file)
      Factory method that creates a new empty File if it is not exists, otherwise it lets the file as it is.
      static java.io.File newFile​(java.io.File parentDirectory, java.lang.String filename)
      Factory method for creating the new File if it is not exists.
      static java.io.File newFile​(java.lang.String absolutePath)
      Factory method that creates a new File object, if the given boolean flag is true a new empty file will be created on the file system
      static java.io.File newFile​(java.lang.String absolutePath, boolean createIfNotExists)
      Factory method that creates a new File object, if the given boolean flag is true a new empty file will be created on the file system
      static java.io.File newFile​(java.lang.String parentDirectory, java.lang.String filename)
      Factory method for creating the new File if it is not exists.
      static java.io.File newFileQuietly​(FileInfo fileInfo)
      Factory method for creating the new File from the given FileInfo object
      static FileCreationState newFileQuietly​(java.io.File file)
      Factory method that creates a new empty File if it is not exists, otherwise it lets the file as it is.
      static java.io.File newFileQuietly​(java.io.File parentDirectory, java.lang.String filename)
      Factory method for creating the new File if it is not exists.
      static java.io.File newFileQuietly​(java.lang.String absolutePath)
      Factory method that creates a new File object, if the given boolean flag is true a new empty file will be created on the file system
      static java.io.File newFileQuietly​(java.lang.String absolutePath, boolean createIfNotExists)
      Factory method that creates a new File object, if the given boolean flag is true a new empty file will be created on the file system
      static java.io.File newFileQuietly​(java.lang.String parentDirectory, java.lang.String filename)
      Factory method for creating the new File if it is not exists.
      static FileCreationState newFiles​(java.util.Collection<java.io.File> files)
      Creates all files contained in the collection as empty files if the files does not exists otherwise it lets the files as they are.
      static FileCreationState newFilesQuietly​(java.util.Collection<java.io.File> files)
      Creates all files contained in the collection as empty files if the files does not exists otherwise it lets the files as they are.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • newDirectories

        public static FileCreationState newDirectories​(java.util.Collection<java.io.File> directories)
        Creates the directories.
        Parameters:
        directories - the directories
        Returns:
        true, if successful
      • newDirectories

        public static boolean newDirectories​(java.nio.file.Path dir,
                                             java.nio.file.attribute.FileAttribute<?>... attrs)
                                      throws java.io.IOException
        Creates a new directory from the given Path object and the optional FileAttribute.

        Note: this method decorates the Files.createDirectories(Path, FileAttribute...) and returns if the directory is created or not.
        Parameters:
        dir - the dir the directory to create
        attrs - an optional list of file attributes to set atomically when creating the directory
        Returns:
        Returns true if the directory was created otherwise false.
        Throws:
        java.io.IOException - Signals that an I/O exception has occurred.
        See Also:
        Files.createDirectories(Path, FileAttribute...)
      • newDirectoriesQuietly

        public static boolean newDirectoriesQuietly​(java.nio.file.Path dir,
                                                    java.nio.file.attribute.FileAttribute<?>... attrs)
        Creates a new directory from the given Path object and the optional FileAttribute.

        Note: this method decorates the Files.createDirectories(Path, FileAttribute...) and returns if the directory is created or not.
        Parameters:
        dir - the dir the directory to create
        attrs - an optional list of file attributes to set atomically when creating the directory
        Returns:
        Returns true if the directory was created otherwise false.
        See Also:
        Files.createDirectories(Path, FileAttribute...)
      • newDirectory

        public static boolean newDirectory​(java.nio.file.Path dir,
                                           java.nio.file.attribute.FileAttribute<?>... attrs)
                                    throws java.io.IOException
        Creates a new directory from the given Path object and the optional FileAttribute.

        Note: this method decorates the Files.createDirectory(Path, FileAttribute...) and returns if the directory is created or not.
        Parameters:
        dir - the dir the directory to create
        attrs - an optional list of file attributes to set atomically when creating the directory
        Returns:
        Returns true if the directory was created otherwise false.
        Throws:
        java.io.IOException - Signals that an I/O exception has occurred.
        See Also:
        Files.createDirectory(Path, FileAttribute...)
      • newDirectoryQuietly

        public static boolean newDirectoryQuietly​(java.nio.file.Path dir,
                                                  java.nio.file.attribute.FileAttribute<?>... attrs)
        Creates a new directory from the given Path object and the optional FileAttribute.

        Note: this method decorates the Files.createDirectory(Path, FileAttribute...) and returns if the directory is created or not.
        Parameters:
        dir - the dir the directory to create
        attrs - an optional list of file attributes to set atomically when creating the directory
        Returns:
        Returns true if the directory was created otherwise false.
        See Also:
        Files.createDirectory(Path, FileAttribute...)
      • newDirectory

        public static java.io.File newDirectory​(java.lang.String absolutePath)
                                         throws java.io.IOException
        Factory method that creates a new File object, if the given boolean flag is true a new empty file will be created on the file system
        Parameters:
        absolutePath - the absolute path
        Returns:
        the file object
        Throws:
        java.io.IOException - Signals that an I/O exception has occurred.
      • newDirectoryQuietly

        public static java.io.File newDirectoryQuietly​(java.lang.String absolutePath)
        Factory method that creates a new File object, if the given boolean flag is true a new empty file will be created on the file system
        Parameters:
        absolutePath - the absolute path
        Returns:
        the file object
      • newDirectory

        public static FileCreationState newDirectory​(java.io.File directory)
        Creates a new directory from the given File object
        Parameters:
        directory - The directory to create
        Returns:
        the FileCreationState with the result
      • newDirectory

        public static java.io.File newDirectory​(java.io.File parentDirectory,
                                                java.lang.String directoryName)
        Factory method for creating the new directory as File objects if it is not exists.
        Parameters:
        parentDirectory - the parent directory
        directoryName - the directory name
        Returns:
        the new directory as File object
      • newDirectory

        public static java.io.File newDirectory​(java.lang.String parentDirectory,
                                                java.lang.String directoryName)
                                         throws java.io.IOException
        Factory method for creating the new directory as File objects if it is not exists.
        Parameters:
        parentDirectory - the parent directory
        directoryName - the directory name
        Returns:
        the new directory as File object
        Throws:
        java.io.IOException - Signals that an I/O exception has occurred.
        See Also:
        Files.createDirectory(Path, FileAttribute...)
      • newDirectoryQuietly

        public static java.io.File newDirectoryQuietly​(java.lang.String parentDirectory,
                                                       java.lang.String directoryName)
        Factory method for creating the new directory as File objects if it is not exists.
        Parameters:
        parentDirectory - the parent directory
        directoryName - the directory name
        Returns:
        the new directory as File object
        See Also:
        Files.createDirectory(Path, FileAttribute...)
      • newFile

        public static FileCreationState newFile​(java.io.File file)
                                         throws java.io.IOException
        Factory method that creates a new empty File if it is not exists, otherwise it lets the file as it is.
        Parameters:
        file - the file.
        Returns:
        the appropriate state object that describes what happen
        Throws:
        java.io.IOException - Signals that an I/O exception has occurred.
      • newFileQuietly

        public static FileCreationState newFileQuietly​(java.io.File file)
        Factory method that creates a new empty File if it is not exists, otherwise it lets the file as it is.
        Parameters:
        file - the file.
        Returns:
        the appropriate state object that describes what happen
      • newFile

        public static java.io.File newFile​(java.lang.String absolutePath)
                                    throws java.io.IOException
        Factory method that creates a new File object, if the given boolean flag is true a new empty file will be created on the file system
        Parameters:
        absolutePath - the absolute path
        Returns:
        the file object
        Throws:
        java.io.IOException - Signals that an I/O exception has occurred.
      • newFileQuietly

        public static java.io.File newFileQuietly​(java.lang.String absolutePath)
        Factory method that creates a new File object, if the given boolean flag is true a new empty file will be created on the file system
        Parameters:
        absolutePath - the absolute path
        Returns:
        the file object
      • newFile

        public static java.io.File newFile​(java.lang.String absolutePath,
                                           boolean createIfNotExists)
                                    throws java.io.IOException
        Factory method that creates a new File object, if the given boolean flag is true a new empty file will be created on the file system
        Parameters:
        absolutePath - the absolute path
        createIfNotExists - if this flag is true the file will be created if it does not exists
        Returns:
        the file object
        Throws:
        java.io.IOException - Signals that an I/O exception has occurred.
      • newFileQuietly

        public static java.io.File newFileQuietly​(java.lang.String absolutePath,
                                                  boolean createIfNotExists)
        Factory method that creates a new File object, if the given boolean flag is true a new empty file will be created on the file system
        Parameters:
        absolutePath - the absolute path
        createIfNotExists - if this flag is true the file will be created if it does not exists
        Returns:
        the file object
      • newFile

        public static java.io.File newFile​(java.io.File parentDirectory,
                                           java.lang.String filename)
                                    throws java.io.IOException
        Factory method for creating the new File if it is not exists.
        Parameters:
        parentDirectory - the parent directory
        filename - the file name
        Returns:
        the new File object
        Throws:
        java.io.IOException - Signals that an I/O exception has occurred.
      • newFileQuietly

        public static java.io.File newFileQuietly​(java.io.File parentDirectory,
                                                  java.lang.String filename)
        Factory method for creating the new File if it is not exists.
        Parameters:
        parentDirectory - the parent directory
        filename - the file name
        Returns:
        the new File object
      • newFile

        public static java.io.File newFile​(java.lang.String parentDirectory,
                                           java.lang.String filename)
                                    throws java.io.IOException
        Factory method for creating the new File if it is not exists.
        Parameters:
        parentDirectory - the parent directory
        filename - the file name
        Returns:
        the new File object
        Throws:
        java.io.IOException - Signals that an I/O exception has occurred.
      • newFileQuietly

        public static java.io.File newFileQuietly​(java.lang.String parentDirectory,
                                                  java.lang.String filename)
        Factory method for creating the new File if it is not exists.
        Parameters:
        parentDirectory - the parent directory
        filename - the file name
        Returns:
        the new File object
      • newFile

        public static java.io.File newFile​(FileInfo fileInfo)
                                    throws java.io.IOException
        Factory method for creating the new File from the given FileInfo object
        Parameters:
        fileInfo - the FileInfo object
        Returns:
        the new File object
        Throws:
        java.io.IOException - Signals that an I/O exception has occurred.
      • newFileQuietly

        public static java.io.File newFileQuietly​(FileInfo fileInfo)
        Factory method for creating the new File from the given FileInfo object
        Parameters:
        fileInfo - the FileInfo object
        Returns:
        the new File object
      • newFiles

        public static FileCreationState newFiles​(java.util.Collection<java.io.File> files)
                                          throws java.io.IOException
        Creates all files contained in the collection as empty files if the files does not exists otherwise it lets the files as they are.
        Parameters:
        files - the Collection with the File objects.
        Returns:
        the FileCreationState object that encapsulate the creation result
        Throws:
        java.io.IOException - Signals that an I/O exception has occurred.
      • newFilesQuietly

        public static FileCreationState newFilesQuietly​(java.util.Collection<java.io.File> files)
        Creates all files contained in the collection as empty files if the files does not exists otherwise it lets the files as they are.
        Parameters:
        files - the Collection with the File objects.
        Returns:
        the FileCreationState object that encapsulate the creation result
      • mkParentDirs

        public static boolean mkParentDirs​(java.io.File file)
        Creates the parent directories from the given file.
        Parameters:
        file - the file
        Returns:
        true, if successful