Class FileUtils
java.lang.Object
com.github.darksoulq.abyssallib.common.util.FileUtils
Utility methods for common file operations such as saving,
deleting, zipping, and hashing files or directories.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidaddFileToZip(File file, String basePath, ZipOutputStream zos) Recursively adds a file or directory to aZipOutputStream.static voidcreateDirectories(File dir) Creates a directory and any nonexistent parent directories.static voiddeleteFolder(Path folder) Recursively deletes a directory and all its contents.getFilePathList(org.bukkit.plugin.Plugin plugin, String basePath) Retrieves a list of resource file paths from a plugin's JAR.static voidsaveFile(InputStream inputStream, File file) Saves the contents of the specifiedInputStreamto the givenFile.static StringComputes the SHA-1 hash of a file.static voidZips an entire directory into a single zip file.
-
Constructor Details
-
FileUtils
public FileUtils()
-
-
Method Details
-
saveFile
Saves the contents of the specifiedInputStreamto the givenFile.- Parameters:
inputStream- the input stream to read data fromfile- the target file to write data to- Throws:
IOException- if an I/O error occurs while reading or writing
-
deleteFolder
Recursively deletes a directory and all its contents.- Parameters:
folder- the path to the directory- Throws:
IOException- if a file or directory could not be deleted
-
createDirectories
Creates a directory and any nonexistent parent directories. Logs an error toSystem.errif creation fails.- Parameters:
dir- the directory to create
-
addFileToZip
Recursively adds a file or directory to aZipOutputStream.- Parameters:
file- the file or directory to addbasePath- the base path to calculate relative paths inside the zipzos- theZipOutputStreamto write to- Throws:
IOException- if an I/O error occurs during zipping
-
getFilePathList
Retrieves a list of resource file paths from a plugin's JAR.- Parameters:
plugin- the plugin to read frombasePath- the base path inside the JAR to search (e.g."assets/")- Returns:
- a list of relative file paths within the JAR
-
zipFolder
-
sha1
Computes the SHA-1 hash of a file.- Parameters:
path- the file path- Returns:
- the SHA-1 hash as a lowercase hex string
- Throws:
RuntimeException- if the file cannot be read or the algorithm is unavailable
-