Package ch.njol.skript.util
Class FileUtils
java.lang.Object
ch.njol.skript.util.FileUtils
-
Method Summary
Modifier and TypeMethodDescriptionstatic FileCreates backup of the provided file inbackupssubdirectory.static voidbackupPurge(File varFile, int toKeep) Deletes files in backup directory to meet desired target, starting from oldest to neweststatic voidstatic voidstatic Stringstatic Filestatic Collection<File> static voidsave(InputStream in, File file) Saves the contents of an InputStream in a file.
-
Method Details
-
getBackupSuffix
- Returns:
- The current date and time
-
backupPurge
public static void backupPurge(File varFile, int toKeep) throws IOException, IllegalArgumentException Deletes files in backup directory to meet desired target, starting from oldest to newest- Parameters:
varFile- Variable file in order to get 'backups' directorytoKeep- Integer of how many files are to be left remaining- Throws:
IOException- If 'backups' directory is not foundIllegalArgumentException- If 'toKeep' parameter is less than 0
-
backup
Creates backup of the provided file inbackupssubdirectory.If compression is enabled using
SkriptConfig.compressBackups, the file is compressed using GZIP.- Parameters:
file- file to create the backup for- Returns:
- the created backup file
- Throws:
IOException- If the backup folder cannot be created, if file with the backup filename already exists, or if IO exception occurs during the copy/compress operation.
-
move
- Throws:
IOException
-
copy
- Throws:
IOException
-
copy
- Throws:
IOException
-
renameAll
public static Collection<File> renameAll(File directory, Converter<String, String> renamer) throws IOException- Parameters:
directory-renamer- Renames files. Return null to leave a file as-is.- Returns:
- A collection of all changed files (with their new names)
- Throws:
IOException- If renaming one of the files caused an IOException. Some files might have been renamed already.
-
save
Saves the contents of an InputStream in a file.- Parameters:
in- The InputStream to read from. This stream will not be closed when this method returns.file- The file to save to. Will be replaced if it exists, or created if it doesn't.- Throws:
IOException
-