Class FileUtils

java.lang.Object
com.github.darksoulq.abyssallib.common.util.FileUtils

public class FileUtils extends Object
Utility methods for common file operations such as saving, deleting, zipping, and hashing files or directories.
  • Constructor Details

    • FileUtils

      public FileUtils()
  • Method Details

    • saveFile

      public static void saveFile(InputStream inputStream, File file) throws IOException
      Saves the contents of the specified InputStream to the given File.
      Parameters:
      inputStream - the input stream to read data from
      file - the target file to write data to
      Throws:
      IOException - if an I/O error occurs while reading or writing
    • deleteFolder

      public static void deleteFolder(Path folder) throws IOException
      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

      public static void createDirectories(File dir)
      Creates a directory and any nonexistent parent directories. Logs an error to System.err if creation fails.
      Parameters:
      dir - the directory to create
    • addFileToZip

      public static void addFileToZip(File file, String basePath, ZipOutputStream zos) throws IOException
      Recursively adds a file or directory to a ZipOutputStream.
      Parameters:
      file - the file or directory to add
      basePath - the base path to calculate relative paths inside the zip
      zos - the ZipOutputStream to write to
      Throws:
      IOException - if an I/O error occurs during zipping
    • getFilePathList

      public static List<String> getFilePathList(org.bukkit.plugin.Plugin plugin, String basePath)
      Retrieves a list of resource file paths from a plugin's JAR.
      Parameters:
      plugin - the plugin to read from
      basePath - the base path inside the JAR to search (e.g. "assets/")
      Returns:
      a list of relative file paths within the JAR
    • zipFolder

      public static void zipFolder(File folder, File zipFile)
      Zips an entire directory into a single zip file.
      Parameters:
      folder - the folder to zip
      zipFile - the resulting zip file
    • sha1

      public static String sha1(Path path)
      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