Contents
- Description
- Field Summary
- Constructor Summary
- Method Summary
- Field Details
- Constructor Details
- Method Details
- unzipFile(Path, byte[], ZipInputStream, ZipEntry, String)
- copyDirectory(Path, Path)
- moveDirectoryContents(Path, Path, CopyOption...)
- deleteDirectory(Path)
- extractZip(Path, Path)
- extractZip(InputStream, Path)
- writeStringAtomic(Path, String, boolean)
- copyToBackup(Path)
- atomicMove(Path, Path)
- writeStringAtomic(Path, String)
Class FileUtil
java.lang.Object
com.hypixel.hytale.server.core.util.io.FileUtil
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final FileVisitOption[]static final Set<FileVisitOption> static final Set<OpenOption> static final Pattern -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidatomicMove(Path source, Path target) Moves a file atomically if supported, otherwise falls back to regular move.static voidcopyDirectory(Path origin, Path destination) static voidcopyToBackup(Path file) Copiesfileto its.baksibling.static voiddeleteDirectory(Path path) static voidextractZip(InputStream inputStream, Path destDir) Extracts a zip from an input stream to a destination directory.static voidextractZip(Path zipFile, Path destDir) Extracts a zip file to a destination directory.static voidmoveDirectoryContents(Path origin, Path destination, CopyOption... options) static voidunzipFile(Path path, byte[] buffer, ZipInputStream zipStream, ZipEntry zipEntry, String name) static voidwriteStringAtomic(Path file, String content) Writes content atomically with backup enabled by default.static voidwriteStringAtomic(Path file, String content, boolean backup) Writes content atomically with optional backup.
-
Field Details
-
DEFAULT_WRITE_OPTIONS
-
DEFAULT_WALK_TREE_OPTIONS_SET
-
DEFAULT_WALK_TREE_OPTIONS_ARRAY
-
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
- Throws:
IOException
-
extractZip
Extracts a zip file to a destination directory.- Parameters:
zipFile- the zip file to extractdestDir- 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 datadestDir- 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 pathcontent- the content to writebackup- whether to keep a .bak backup of the previous version- Throws:
IOException
-
copyToBackup
Copiesfileto its.baksibling. Does nothing iffiledoes 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.tmpand 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
.bakthen holds a version older than the one being replaced, which costs less than dropping the new content. A.bak.tmpleft by a failed rename still holds a good copy, and the next write replaces it. -
atomicMove
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
-