Class NBTReader

java.lang.Object
de.pauleff.formats.binary.NBTReader
All Implemented Interfaces:
INBTReader, AutoCloseable

public class NBTReader extends Object implements INBTReader
Class for handling the parsing and formatting of a Java NBT file.
Author:
Paul Ferlitz
  • Constructor Details

    • NBTReader

      public NBTReader(File nbtFile)
      Create a reader by passing it the target NBT file.
      Parameters:
      nbtFile - The target NBT file.
    • NBTReader

      public NBTReader(DataInputStream dis)
      Create a reader by passing it a DataInputStream.
      Parameters:
      dis - A DataInputStream containing a NBT file.
  • Method Details

    • byteArrayToDataInputStream

      public static PositionTrackingDataInputStream byteArrayToDataInputStream(byte[] chunkData)
      Converts a byte array into a position-tracking DataInputStream for NBT reading.
      Parameters:
      chunkData - The byte array to convert
      Returns:
      A PositionTrackingDataInputStream for enhanced error reporting
    • close

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

      public ICompoundTag read() throws IOException
      Parses the NBT file and returns the root compound tag. This method automatically closes the reader when parsing is complete or if an error occurs.
      Specified by:
      read in interface INBTReader
      Returns:
      The root ICompoundTag containing the complete NBT structure
      Throws:
      IOException - If the file cannot be read, is corrupted, or doesn't follow NBT specification