Class FileSystem

java.lang.Object
dev.prozilla.pine.common.system.FileSystem

public final class FileSystem extends Object
Utility class for manipulating files and directories.
  • Method Details

    • deleteDirectoryIfExists

      public static boolean deleteDirectoryIfExists(Path directory)
      Deletes a directory and its contents, if it exists.
      Parameters:
      directory - The directory to delete
      Returns:
      true if the directory was deleted.
    • deleteDirectory

      public static void deleteDirectory(Path directory)
      Deletes a directory and its contents.
      Parameters:
      directory - The directory to delete
    • copyDirectory

      public static void copyDirectory(File source, File target) throws IOException
      Helper method for copying a directory and its contents recursively.
      Parameters:
      source - The directory to copy from
      target - The directory to paste into
      Throws:
      IOException
    • getSubdirectory

      public static Path getSubdirectory(Path directory) throws IOException
      Throws:
      IOException
    • unwrapDirectory

      public static void unwrapDirectory(Path directory) throws IOException
      Moves the contents of a directory one level up and deletes the directory.
      Parameters:
      directory - The directory to unwrap
      Throws:
      IOException
    • download

      public static void download(String url, Path target) throws URISyntaxException, IOException
      Downloads a URL into a target directory.
      Parameters:
      url - The URL to download from
      target - The path to download to
      Throws:
      URISyntaxException
      IOException
    • unzip

      public static void unzip(Path zip, Path target) throws IOException
      Unzips a zip file into a target directory and deletes it.
      Parameters:
      zip - The zip to unzip
      target - The path to unzip into
      Throws:
      IOException
    • zip

      public static void zip(Path directory, String fileName) throws IOException
      Creates a zip of the contents of a directory. The zip file is placed inside the same directory.
      Parameters:
      directory - The directory to create a zip of
      fileName - The filename to use for the zip file
      Throws:
      IOException