类 IOUtilities
java.lang.Object
net.neoforged.neoforge.common.IOUtilities
Contains helpers for performing file I/O in a resilient manner.
-
嵌套类概要
嵌套类修饰符和类型类说明static interface
Declares an interface which is functionally equivalent toConsumer
, except supports the ability to throw IOExceptions that may occur. -
字段概要
字段修饰符和类型字段说明private static final org.slf4j.Logger
private static final OpenOption[]
private static final String
-
构造器概要
构造器 -
方法概要
修饰符和类型方法说明static void
atomicWrite
(Path targetPath, IOUtilities.WriteCallback writeCallback) Writes data to the given path "atomically", such that a crash will not leave the file containing corrupted or otherwise half-written data.private static BiPredicate
<Path, BasicFileAttributes> createPredicate
(@Nullable String prefix) static void
tryCleanupTempFiles
(Path targetPath, @Nullable String prefix) Tries to clean up any temporary files that may have been left over from interrupted calls toatomicWrite(Path, WriteCallback)
.tryListTempFiles
(Path targetPath, @Nullable String prefix) static void
writeNbt
(CompoundTag tag, Path path) Behaves much the same asNbtIo.write(CompoundTag, Path)
, but usesatomicWrite(Path, WriteCallback)
behind the scenes to ensure the data is stored resiliently.static void
writeNbtCompressed
(CompoundTag tag, Path path) Behaves much the same asNbtIo.writeCompressed(CompoundTag, Path)
, but usesatomicWrite(Path, WriteCallback)
behind the scenes to ensure the data is stored resiliently.
-
字段详细资料
-
TEMP_FILE_SUFFIX
- 另请参阅:
-
OPEN_OPTIONS
-
LOGGER
private static final org.slf4j.Logger LOGGER
-
-
构造器详细资料
-
IOUtilities
private IOUtilities()
-
-
方法详细资料
-
tryCleanupTempFiles
Tries to clean up any temporary files that may have been left over from interrupted calls toatomicWrite(Path, WriteCallback)
.Failures to find or remove the temporary files are logged instead of thrown.
- 参数:
targetPath
- The target path to clean up temporary files in.prefix
- The prefix of temporary files to clean up, or null if all temporary files should be removed.
-
tryListTempFiles
-
createPredicate
private static BiPredicate<Path,BasicFileAttributes> createPredicate(@Nullable @Nullable String prefix) -
writeNbtCompressed
Behaves much the same asNbtIo.writeCompressed(CompoundTag, Path)
, but usesatomicWrite(Path, WriteCallback)
behind the scenes to ensure the data is stored resiliently.- 参数:
tag
- The tag to write.path
- The path to write the NBT to.- 抛出:
IOException
- if an I/O error occurs during writing.
-
writeNbt
Behaves much the same asNbtIo.write(CompoundTag, Path)
, but usesatomicWrite(Path, WriteCallback)
behind the scenes to ensure the data is stored resiliently.- 参数:
tag
- The tag to write.path
- The path to write the NBT to.- 抛出:
IOException
- if an I/O error occurs during writing.
-
atomicWrite
public static void atomicWrite(Path targetPath, IOUtilities.WriteCallback writeCallback) throws IOException Writes data to the given path "atomically", such that a crash will not leave the file containing corrupted or otherwise half-written data.This method operates by creating a temporary file, writing to that file, and then moving the temporary file to the correct location after flushing. If a crash occurs during this process, the temporary file will be abandoned.
Furthermore, the stream passed to
writeCallback
is not buffered, and it is the handler's responsibility to implement any buffering on top of this method.- 参数:
targetPath
- The desired path to write to.writeCallback
- A callback which receives the opened stream to write data to.- 抛出:
IOException
- if an I/O error occurs during writing.
-