Class FileUtils

java.lang.Object
io.github.toberocat.guiengine.utils.FileUtils

public class FileUtils extends Object
FileUtils is a utility class providing file-related operations for Java plugins.

Created: 21.07.2023 Author: Tobias Madlberger (Tobias)

  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static @NotNull File
    copyAll(@NotNull org.bukkit.plugin.java.JavaPlugin plugin, @NotNull String root)
    Copies all files and directories from the specified root folder within the plugin's JAR file to the plugin's data folder.
    static void
    copyResource(@NotNull org.bukkit.plugin.java.JavaPlugin plugin, @NotNull String res)
    Copies a resource file from the plugin's JAR file to the plugin's data folder.
    static void
    foreachIn(@NotNull org.bukkit.plugin.java.JavaPlugin plugin, @NotNull String root, @NotNull Consumer<Path> consumer)
    Lists all files and directories within the specified root folder within the plugin's JAR file.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • FileUtils

      public FileUtils()
  • Method Details

    • copyAll

      @NotNull public static @NotNull File copyAll(@NotNull @NotNull org.bukkit.plugin.java.JavaPlugin plugin, @NotNull @NotNull String root) throws IOException, URISyntaxException
      Copies all files and directories from the specified root folder within the plugin's JAR file to the plugin's data folder. If a folder is encountered during the copying process, it recursively copies its contents as well.
      Parameters:
      plugin - The JavaPlugin instance of the plugin.
      root - The root folder within the JAR file to copy from.
      Returns:
      The File representing the root folder in the plugin's data folder after copying.
      Throws:
      IOException - If an I/O error occurs during copying.
      URISyntaxException - If the plugin's root URL cannot be converted to a URI.
    • foreachIn

      public static void foreachIn(@NotNull @NotNull org.bukkit.plugin.java.JavaPlugin plugin, @NotNull @NotNull String root, @NotNull @NotNull Consumer<Path> consumer) throws URISyntaxException, IOException
      Lists all files and directories within the specified root folder within the plugin's JAR file.
      Parameters:
      plugin - The JavaPlugin instance of the plugin.
      root - The root folder within the JAR file to list from.
      Throws:
      URISyntaxException - If the plugin's root URL cannot be converted to a URI.
      IOException - If an I/O error occurs while listing the files and directories.
    • copyResource

      public static void copyResource(@NotNull @NotNull org.bukkit.plugin.java.JavaPlugin plugin, @NotNull @NotNull String res) throws IOException
      Copies a resource file from the plugin's JAR file to the plugin's data folder.
      Parameters:
      plugin - The JavaPlugin instance of the plugin.
      res - The resource file path within the JAR file to copy.
      Throws:
      IOException - If an I/O error occurs during copying.