Class FileUtil

java.lang.Object
com.hypixel.hytale.server.core.util.io.FileUtil

public class FileUtil extends Object
  • Field Details

    • DEFAULT_WRITE_OPTIONS

      public static final Set<OpenOption> DEFAULT_WRITE_OPTIONS
    • DEFAULT_WALK_TREE_OPTIONS_SET

      public static final Set<FileVisitOption> DEFAULT_WALK_TREE_OPTIONS_SET
    • DEFAULT_WALK_TREE_OPTIONS_ARRAY

      public static final FileVisitOption[] DEFAULT_WALK_TREE_OPTIONS_ARRAY
    • INVALID_FILENAME_CHARACTERS

      public static final Pattern INVALID_FILENAME_CHARACTERS
  • Constructor Details

    • FileUtil

      public FileUtil()
  • Method Details

    • unzipFile

      public static void unzipFile(@Nonnull Path path, @Nonnull byte[] buffer, @Nonnull ZipInputStream zipStream, @Nonnull ZipEntry zipEntry, @Nonnull String name) throws IOException
      Throws:
      IOException
    • copyDirectory

      public static void copyDirectory(@Nonnull Path origin, @Nonnull Path destination) throws IOException
      Throws:
      IOException
    • moveDirectoryContents

      public static void moveDirectoryContents(@Nonnull Path origin, @Nonnull Path destination, CopyOption... options) throws IOException
      Throws:
      IOException
    • deleteDirectory

      public static void deleteDirectory(@Nonnull Path path) throws IOException
      Throws:
      IOException
    • extractZip

      public static void extractZip(@Nonnull Path zipFile, @Nonnull Path destDir) throws IOException
      Extracts a zip file to a destination directory.
      Parameters:
      zipFile - the zip file to extract
      destDir - the destination directory
      Throws:
      IOException
    • extractZip

      public static void extractZip(@Nonnull InputStream inputStream, @Nonnull Path destDir) throws IOException
      Extracts a zip from an input stream to a destination directory.
      Parameters:
      inputStream - the input stream containing zip data
      destDir - the destination directory
      Throws:
      IOException
    • writeStringAtomic

      public static void writeStringAtomic(@Nonnull Path file, @Nonnull String content, boolean backup) throws IOException
      Writes content atomically with optional backup. Pattern: write to .tmp → copy primary to .bak → rename .tmp to primary
      Parameters:
      file - the target file path
      content - the content to write
      backup - whether to keep a .bak backup of the previous version
      Throws:
      IOException
    • copyToBackup

      public static void copyToBackup(@Nonnull Path file)
      Copies file to its .bak sibling. Does nothing if file does not exist.

      The copy leaves the primary in place, so a later failure to promote a new version cannot leave the primary missing. The copy lands in .bak.tmp and is then renamed onto .bak, so the backup is only ever replaced whole. A failure part way through cannot leave a partial backup.

      A failed backup does not fail the caller's write. The .bak then holds a version older than the one being replaced, which costs less than dropping the new content. A .bak.tmp left by a failed rename still holds a good copy, and the next write replaces it.

    • atomicMove

      public static void atomicMove(@Nonnull Path source, @Nonnull Path target) throws IOException
      Moves a file atomically if supported, otherwise falls back to regular move. Same-filesystem moves are atomic on all major platforms (Linux, macOS, Windows).

      Retries while another process holds the source or the target open.

      Throws:
      IOException
    • writeStringAtomic

      public static void writeStringAtomic(@Nonnull Path file, @Nonnull String content) throws IOException
      Writes content atomically with backup enabled by default.
      Throws:
      IOException