Class PositionTrackingDataInputStream

java.lang.Object
de.pauleff.formats.binary.PositionTrackingDataInputStream

public class PositionTrackingDataInputStream extends Object
Enhanced DataInputStream wrapper that tracks read position for better error reporting. Provides detailed context about where in the stream parsing errors occur.
Author:
Paul Ferlitz
  • Constructor Details

    • PositionTrackingDataInputStream

      public PositionTrackingDataInputStream(InputStream in)
      Creates a position tracking input stream.
      Parameters:
      in - The underlying input stream to wrap
  • Method Details

    • readFully

      public void readFully(byte[] b) throws IOException
      Throws:
      IOException
    • readFully

      public void readFully(byte[] b, int off, int len) throws IOException
      Throws:
      IOException
    • readByte

      public byte readByte() throws IOException
      Throws:
      IOException
    • readUnsignedByte

      public int readUnsignedByte() throws IOException
      Throws:
      IOException
    • readShort

      public short readShort() throws IOException
      Throws:
      IOException
    • readUnsignedShort

      public int readUnsignedShort() throws IOException
      Throws:
      IOException
    • readInt

      public int readInt() throws IOException
      Throws:
      IOException
    • readLong

      public long readLong() throws IOException
      Throws:
      IOException
    • readFloat

      public float readFloat() throws IOException
      Throws:
      IOException
    • readDouble

      public double readDouble() throws IOException
      Throws:
      IOException
    • close

      public void close() throws IOException
      Throws:
      IOException
    • getBytesRead

      public long getBytesRead()
      Returns the current position in the stream.
      Returns:
      Number of bytes read so far
    • getTagDepth

      public int getTagDepth()
      Returns the current nesting depth in the NBT structure.
      Returns:
      Current tag depth (0 = root)
    • setCurrentContext

      public void setCurrentContext(int depth, String tagName, int tagType)
      Sets the current tag context for error reporting.
      Parameters:
      depth - Current nesting depth
      tagName - Name of the tag being parsed
      tagType - Type ID of the tag being parsed
    • createContextualError

      public String createContextualError(String baseMessage)
      Creates a detailed error message with current parsing context.
      Parameters:
      baseMessage - The base error message
      Returns:
      Enhanced error message with position and context