Class NBTWriter

java.lang.Object
de.pauleff.formats.binary.NBTWriter
All Implemented Interfaces:
INBTWriter, AutoCloseable

public class NBTWriter extends Object implements INBTWriter
Class for handling the writing of Java NBT to file.
Author:
Paul Ferlitz
  • Constructor Details

    • NBTWriter

      public NBTWriter(File nbtFile) throws FileNotFoundException
      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

      public NBTWriter(File nbtFile, Compression_Types compression)
      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

      public NBTWriter(DataOutputStream dos)
      Create a writer by passing it the target NBT file as a DataOutputStream.
      Parameters:
      dos - A DataOutputStream containing a NBT file.
  • Method Details

    • close

      public void close() throws IOException
      Method to close the writer.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface INBTWriter
      Throws:
      IOException - When encountering an error whilst closing the writer.
    • write

      public void write(ICompoundTag root) throws IOException
      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:
      write in interface INBTWriter
      Parameters:
      root - The root ICompoundTag containing the complete NBT structure to write
      Throws:
      IOException - If an error occurs during file writing or if the data is invalid
      IllegalArgumentException - If root is null