Package com.palmergames.util
Class FileMgmt
java.lang.Object
com.palmergames.util.FileMgmt
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
checkOrCreateFile
(String filePath) Checks a filePath to see if it exists, if it doesn't it will attempt to create the file at the designated path.static boolean
checkOrCreateFiles
(String... files) Checks an array of folderPaths to see if they exist, if they don't it will try to create the folder at the designated paths.static boolean
checkOrCreateFolder
(String folderPath) Checks a folderPath to see if it exists, if it doesn't it will attempt to create the folder at the designated path.static boolean
checkOrCreateFolders
(String... folders) Checks an array of folderPaths to see if they exist, if they don't it will try to create the folder at the designated paths.static void
copyDirectory
(File sourceLocation, File targetLocation) static void
deleteFile
(File file) Delete file, or if path represents a directory, recursively delete it's contents beforehand.static boolean
deleteOldBackups
(File backupsDir, long deleteAfter) Delete child files/folders of backupsDir with a filename ending in milliseconds that is older than deleteAfter milliseconds in age.static @NotNull String
getExtension
(@NotNull Path path) static @NotNull String
getFileName
(@NotNull Path path) static String
static boolean
listToFile
(Collection<String> source, String targetLocation) Write a list to a file, terminating each line with a system specific new line.loadFileIntoHashMap
(File file) Function which reads from a resident, town, nation, townyobject file, returning a hashmap.static void
static void
moveTownBlockFile
(File sourceFile, String targetLocation, String townDir) static void
recursiveZipDirectory
(File sourceFolder, ZipOutputStream zipStream) static void
savePlotData
(PlotBlockData data, File file, String path) Method to save a PlotBlockData object to disk.static void
static void
writeString
(Path path, String string) static void
zipDirectories
(File destination, File... sourceFolders) static void
Zip a given file into the given path.
-
Constructor Details
-
FileMgmt
public FileMgmt()
-
-
Method Details
-
checkOrCreateFolder
Checks a folderPath to see if it exists, if it doesn't it will attempt to create the folder at the designated path.- Parameters:
folderPath
-String
containing a path to a folder.- Returns:
- True if the folder exists or if it was successfully created.
-
checkOrCreateFolders
Checks an array of folderPaths to see if they exist, if they don't it will try to create the folder at the designated paths.- Parameters:
folders
- array ofString
containing a path to a folder.- Returns:
- true or false
-
checkOrCreateFile
Checks a filePath to see if it exists, if it doesn't it will attempt to create the file at the designated path.- Parameters:
filePath
-String
containing a path to a file.- Returns:
- True if the folder exists or if it was successfully created.
-
checkOrCreateFiles
Checks an array of folderPaths to see if they exist, if they don't it will try to create the folder at the designated paths.- Parameters:
files
- array ofString
containing a path to a file.- Returns:
- true or false
-
copyDirectory
- Throws:
IOException
-
listToFile
Write a list to a file, terminating each line with a system specific new line.- Parameters:
source
- - Data sourcetargetLocation
- - Target location on Filesystem- Returns:
- true on success, false on IOException
-
moveFile
-
moveTownBlockFile
-
getFileTimeStamp
-
tar
- Throws:
IOException
-
zipFile
Zip a given file into the given path.- Parameters:
file
- - File to zip.path
- - Path to put file.
-
zipDirectories
- Throws:
IOException
-
recursiveZipDirectory
public static void recursiveZipDirectory(File sourceFolder, ZipOutputStream zipStream) throws IOException - Throws:
IOException
-
deleteFile
Delete file, or if path represents a directory, recursively delete it's contents beforehand.- Parameters:
file
- -File
to delete
-
deleteOldBackups
Delete child files/folders of backupsDir with a filename ending in milliseconds that is older than deleteAfter milliseconds in age.- Parameters:
backupsDir
- -File
path to backupsDirdeleteAfter
- - Maximum age of files, in milliseconds- Returns:
- Whether old backups were successfully deleted.
-
loadFileIntoHashMap
Function which reads from a resident, town, nation, townyobject file, returning a hashmap.- Parameters:
file
- - File from which the HashMap will be made.- Returns:
- HashMap - Used for loading keys and values from object files.
-
savePlotData
Method to save a PlotBlockData object to disk.- Parameters:
data
- PlotBlockData object containing a plot snapshot used for the unclaim-on-revert feature.file
- Directory to save the PlotBlockData to.path
- Zip file location to save to.
-
writeString
- Throws:
IOException
-
getFileName
- Parameters:
path
- The file path- Returns:
- The file name for the given path (minus file extension)
-
getExtension
-