Class NBTWriter
java.lang.Object
de.pauleff.formats.binary.NBTWriter
- All Implemented Interfaces:
INBTWriter,AutoCloseable
Class for handling the writing of Java NBT to file.
- Author:
- Paul Ferlitz
-
Constructor Summary
ConstructorsConstructorDescriptionCreate a writer by passing it the target NBT file as aDataOutputStream.Create a writer by passing it the target NBT file.NBTWriter(File nbtFile, Compression_Types compression) Create a writer by passing it the target NBT file and how to compress it. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Method to close the writer.voidwrite(ICompoundTag root) Writes the compound tag structure to file and closes the writer.
-
Constructor Details
-
NBTWriter
Create a writer by passing it the target NBT file. Target file must already exist to determine the compression type. A backup of the target file will be made before overwriting it.- Parameters:
nbtFile- The target NBT file.- Throws:
FileNotFoundException
-
NBTWriter
Create a writer by passing it the target NBT file and how to compress it. A backup of the target file will be made before overwriting it, if it exists.- Parameters:
nbtFile- The target NBT file.compression- The compression type of the file.
-
NBTWriter
Create a writer by passing it the target NBT file as aDataOutputStream.- Parameters:
dos- ADataOutputStreamcontaining a NBT file.
-
-
Method Details
-
close
Method to close the writer.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceINBTWriter- Throws:
IOException- When encountering an error whilst closing the writer.
-
write
Writes the compound tag structure to file and closes the writer. The NBT specification requires compound tags as file roots, so this method enforces that constraint.- Specified by:
writein interfaceINBTWriter- Parameters:
root- The rootICompoundTagcontaining the complete NBT structure to write- Throws:
IOException- If an error occurs during file writing or if the data is invalidIllegalArgumentException- If root is null
-