Class FileMgmt

java.lang.Object
com.palmergames.util.FileMgmt

public final class FileMgmt extends Object
  • Constructor Details

    • FileMgmt

      public FileMgmt()
  • Method Details

    • checkOrCreateFolder

      public static boolean checkOrCreateFolder(String folderPath)
      Checks a folderPath to see if it exists, if it doesn't it will attempt to create the folder at the designated path.
      Parameters:
      folderPath - String containing a path to a folder.
      Returns:
      True if the folder exists or if it was successfully created.
    • checkOrCreateFolders

      public static boolean checkOrCreateFolders(String... folders)
      Checks an array of folderPaths to see if they exist, if they don't it will try to create the folder at the designated paths.
      Parameters:
      folders - array of String containing a path to a folder.
      Returns:
      true or false
    • checkOrCreateFile

      public static boolean checkOrCreateFile(String filePath)
      Checks a filePath to see if it exists, if it doesn't it will attempt to create the file at the designated path.
      Parameters:
      filePath - String containing a path to a file.
      Returns:
      True if the folder exists or if it was successfully created.
    • checkOrCreateFiles

      public static boolean checkOrCreateFiles(String... files)
      Checks an array of folderPaths to see if they exist, if they don't it will try to create the folder at the designated paths.
      Parameters:
      files - array of String containing a path to a file.
      Returns:
      true or false
    • copyDirectory

      public static void copyDirectory(File sourceLocation, File targetLocation) throws IOException
      Throws:
      IOException
    • listToFile

      public static boolean listToFile(Collection<String> source, String targetLocation)
      Write a list to a file, terminating each line with a system specific new line.
      Parameters:
      source - - Data source
      targetLocation - - Target location on Filesystem
      Returns:
      true on success, false on IOException
    • moveFile

      public static void moveFile(File sourceFile, String targetLocation)
    • moveTownBlockFile

      public static void moveTownBlockFile(File sourceFile, String targetLocation, String townDir)
    • getFileTimeStamp

      public static String getFileTimeStamp()
    • tar

      public static void tar(File destination, File... sources) throws IOException
      Throws:
      IOException
    • zipFile

      public static void zipFile(File file, String path)
      Zip a given file into the given path.
      Parameters:
      file - - File to zip.
      path - - Path to put file.
    • zipDirectories

      public static void zipDirectories(File destination, File... sourceFolders) throws IOException
      Throws:
      IOException
    • recursiveZipDirectory

      public static void recursiveZipDirectory(File sourceFolder, ZipOutputStream zipStream) throws IOException
      Throws:
      IOException
    • deleteFile

      public static void deleteFile(File file)
      Delete file, or if path represents a directory, recursively delete it's contents beforehand.
      Parameters:
      file - - File to delete
    • deleteOldBackups

      public static boolean deleteOldBackups(File backupsDir, long deleteAfter)
      Delete child files/folders of backupsDir with a filename ending in milliseconds that is older than deleteAfter milliseconds in age.
      Parameters:
      backupsDir - - File path to backupsDir
      deleteAfter - - Maximum age of files, in milliseconds
      Returns:
      Whether old backups were successfully deleted.
    • loadFileIntoHashMap

      public static HashMap<String,String> loadFileIntoHashMap(File file)
      Function which reads from a resident, town, nation, townyobject file, returning a hashmap.
      Parameters:
      file - - File from which the HashMap will be made.
      Returns:
      HashMap - Used for loading keys and values from object files.
    • savePlotData

      public static void savePlotData(PlotBlockData data, File file, String path)
      Method to save a PlotBlockData object to disk.
      Parameters:
      data - PlotBlockData object containing a plot snapshot used for the unclaim-on-revert feature.
      file - Directory to save the PlotBlockData to.
      path - Zip file location to save to.
    • writeString

      public static void writeString(Path path, String string) throws IOException
      Throws:
      IOException
    • getFileName

      @NotNull public static @NotNull String getFileName(@NotNull @NotNull Path path)
      Parameters:
      path - The file path
      Returns:
      The file name for the given path (minus file extension)
    • getExtension

      @NotNull public static @NotNull String getExtension(@NotNull @NotNull Path path)