Package io.github.astrapi69.file.create
Class FileFactory
- java.lang.Object
-
- io.github.astrapi69.file.create.FileFactory
-
public final class FileFactory extends java.lang.Object
The classFileFactory
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 givenPath
object and the optionalFileAttribute
.
Note: this method decorates theFiles.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 givenPath
object and the optionalFileAttribute
.
Note: this method decorates theFiles.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 givenFile
objectstatic java.io.File
newDirectory(java.io.File parentDirectory, java.lang.String directoryName)
Factory method for creating the new directory asFile
objects if it is not exists.static java.io.File
newDirectory(java.lang.String absolutePath)
Factory method that creates a newFile
object, if the given boolean flag is true a new empty file will be created on the file systemstatic java.io.File
newDirectory(java.lang.String parentDirectory, java.lang.String directoryName)
Factory method for creating the new directory asFile
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 givenPath
object and the optionalFileAttribute
.
Note: this method decorates theFiles.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 newFile
object, if the given boolean flag is true a new empty file will be created on the file systemstatic java.io.File
newDirectoryQuietly(java.lang.String parentDirectory, java.lang.String directoryName)
Factory method for creating the new directory asFile
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 givenPath
object and the optionalFileAttribute
.
Note: this method decorates theFiles.createDirectory(Path, FileAttribute...)
and returns if the directory is created or not.static java.io.File
newFile(FileInfo fileInfo)
Factory method for creating the newFile
from the givenFileInfo
objectstatic FileCreationState
newFile(java.io.File file)
Factory method that creates a new emptyFile
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 newFile
if it is not exists.static java.io.File
newFile(java.lang.String absolutePath)
Factory method that creates a newFile
object, if the given boolean flag is true a new empty file will be created on the file systemstatic java.io.File
newFile(java.lang.String absolutePath, boolean createIfNotExists)
Factory method that creates a newFile
object, if the given boolean flag is true a new empty file will be created on the file systemstatic java.io.File
newFile(java.lang.String parentDirectory, java.lang.String filename)
Factory method for creating the newFile
if it is not exists.static java.io.File
newFileQuietly(FileInfo fileInfo)
Factory method for creating the newFile
from the givenFileInfo
objectstatic FileCreationState
newFileQuietly(java.io.File file)
Factory method that creates a new emptyFile
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 newFile
if it is not exists.static java.io.File
newFileQuietly(java.lang.String absolutePath)
Factory method that creates a newFile
object, if the given boolean flag is true a new empty file will be created on the file systemstatic java.io.File
newFileQuietly(java.lang.String absolutePath, boolean createIfNotExists)
Factory method that creates a newFile
object, if the given boolean flag is true a new empty file will be created on the file systemstatic java.io.File
newFileQuietly(java.lang.String parentDirectory, java.lang.String filename)
Factory method for creating the newFile
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.
-
-
-
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 givenPath
object and the optionalFileAttribute
.
Note: this method decorates theFiles.createDirectories(Path, FileAttribute...)
and returns if the directory is created or not.- Parameters:
dir
- the dir the directory to createattrs
- 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 givenPath
object and the optionalFileAttribute
.
Note: this method decorates theFiles.createDirectories(Path, FileAttribute...)
and returns if the directory is created or not.- Parameters:
dir
- the dir the directory to createattrs
- 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 givenPath
object and the optionalFileAttribute
.
Note: this method decorates theFiles.createDirectory(Path, FileAttribute...)
and returns if the directory is created or not.- Parameters:
dir
- the dir the directory to createattrs
- 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 givenPath
object and the optionalFileAttribute
.
Note: this method decorates theFiles.createDirectory(Path, FileAttribute...)
and returns if the directory is created or not.- Parameters:
dir
- the dir the directory to createattrs
- 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 newFile
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 newFile
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 givenFile
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 asFile
objects if it is not exists.- Parameters:
parentDirectory
- the parent directorydirectoryName
- 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 asFile
objects if it is not exists.- Parameters:
parentDirectory
- the parent directorydirectoryName
- 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 asFile
objects if it is not exists.- Parameters:
parentDirectory
- the parent directorydirectoryName
- 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 emptyFile
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 emptyFile
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 newFile
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 newFile
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 newFile
object, if the given boolean flag is true a new empty file will be created on the file system- Parameters:
absolutePath
- the absolute pathcreateIfNotExists
- 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 newFile
object, if the given boolean flag is true a new empty file will be created on the file system- Parameters:
absolutePath
- the absolute pathcreateIfNotExists
- 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 newFile
if it is not exists.- Parameters:
parentDirectory
- the parent directoryfilename
- 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 newFile
if it is not exists.- Parameters:
parentDirectory
- the parent directoryfilename
- 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 newFile
if it is not exists.- Parameters:
parentDirectory
- the parent directoryfilename
- 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 newFile
if it is not exists.- Parameters:
parentDirectory
- the parent directoryfilename
- 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 newFile
from the givenFileInfo
object- Parameters:
fileInfo
- theFileInfo
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 newFile
from the givenFileInfo
object- Parameters:
fileInfo
- theFileInfo
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
-
-