Class FileUtil
java.lang.Object
nl.pim16aap2.animatedarchitecture.core.util.FileUtil
Utility class for file operations.
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidappendToFile(Path path, List<String> append) Appends a list of strings to a file.static FileSystemcreateNewFileSystem(Path zipFile) Creates a newFileSystemfor a zip file.static voiddeleteFile(Path file) Deletes a file if it exists.static voidEnsures a directory exists.static PathensureFileExists(Path file) Ensures that a file exists.static voidensureZipFileExists(Path zipFile) Ensures a given zip file exists.getFilesInJar(Path jarFile, Pattern pattern) Gets the names of all files inside a jar that match a certain pattern.static PathgetJarFile(Class<?> clz) Gets the file of the jar that contained a specific class.
-
Method Details
-
deleteFile
Deletes a file if it exists.If an exception occurs while deleting the file, it will be logged, but the method will not throw an exception.
If the file does not exist, nothing happens.
- Parameters:
file- The file to delete.
-
ensureFileExists
Ensures that a file exists.If the file does not already exist, it will be created.
- Parameters:
file- The file whose existence to ensure.- Returns:
- The path to the file.
- Throws:
IOException- When the file could not be created.
-
appendToFile
-
ensureDirectoryExists
Ensures a directory exists. -
ensureZipFileExists
Ensures a given zip file exists. -
getJarFile
-
createNewFileSystem
public static FileSystem createNewFileSystem(Path zipFile) throws IOException, URISyntaxException, ProviderNotFoundException Creates a newFileSystemfor a zip file.Don't forget to close it when you're done!
- Parameters:
zipFile- The zip file for which to create a new FileSystem.- Returns:
- The newly created FileSystem.
- Throws:
IOException- If an I/O error occurs creating the file system.FileSystemAlreadyExistsException- When a FileSystem already exists for the provided file.URISyntaxExceptionProviderNotFoundException
-
getFilesInJar
Gets the names of all files inside a jar that match a certain pattern.- Parameters:
jarFile- The jar file to search in.pattern- The pattern to match the file names against.- Returns:
- The names of all files in the jar that match the pattern.
- Throws:
IOException- If an I/O error occurs.
-