Record Class RiffChunk

java.lang.Object
java.lang.Record
com.tino1b2be.dtmf.io.wav.internal.RiffChunk
Record Components:
id - the four-character chunk identifier; must be non-null
size - declared payload length in bytes; must be non-negative
dataStartOffset - absolute byte position of the first payload byte within the enclosing source; must be non-negative

public record RiffChunk(String id, long size, long dataStartOffset) extends Record
Header metadata for a single RIFF chunk inside a WAV container.

A RIFF chunk is a length-prefixed, ID-tagged run of bytes: four ASCII characters of id (for example "fmt ", "data", "LIST", or "ds64"), a 32-bit little-endian size field giving the number of payload bytes that follow the 8-byte header, and then size bytes of payload — plus one zero-byte pad when size is odd, carried at the next higher level by RiffReader.

This record describes only the chunk's header. It does not hold the payload itself: the WAV reader streams the payload directly through RiffReader.skip(long) for ignored chunks and through fmt /ds64 parsers for chunks the provider understands. dataStartOffset() is the absolute byte position of the first payload byte within the enclosing source (file or stream), measured from the same origin as RiffReader.position().

Contract:

  • id is the four-character chunk identifier, exactly four ASCII bytes interpreted as StandardCharsets.US_ASCII. Must be non-null. RiffReader produces IDs by calling readAscii(4), which in turn enforces the length invariant, so callers constructing a RiffChunk by hand (test fixtures, for example) must keep the same shape.
  • size is the declared payload length in bytes, from the chunk's 32-bit little-endian size field, promoted to long because WAV's size field is unsigned 32-bit and the natural Java int would sign-flip at 2 GiB. For RF64 files the outer RIFF/RF64 and data chunks use an 0xFFFFFFFF sentinel here and the real size is pulled from the ds64 chunk by the caller. Must be non-negative.
  • dataStartOffset is the absolute byte position of the chunk's payload within the underlying source, i.e. the position immediately after the 8-byte ID+size header. Must be non-negative.

This record is not part of the published API. It lives in com.tino1b2be.dtmf.io.wav.internal, whose stability contract (see the package Javadoc) explicitly allows breakage between any two releases. It is public at the type level purely so classes in the parent com.tino1b2be.dtmf.io.wav package can reach it; external callers MUST NOT depend on it.

Since:
2.1.0
  • Constructor Summary

    Constructors
    Constructor
    Description
    RiffChunk(String id, long size, long dataStartOffset)
    Compact constructor validating the non-null and non-negative invariants.
  • Method Summary

    Modifier and Type
    Method
    Description
    long
    Returns the value of the dataStartOffset record component.
    final boolean
    Indicates whether some other object is "equal to" this one.
    final int
    Returns a hash code value for this object.
    id()
    Returns the value of the id record component.
    long
    Returns the value of the size record component.
    final String
    Returns a string representation of this record class.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • RiffChunk

      public RiffChunk(String id, long size, long dataStartOffset)
      Compact constructor validating the non-null and non-negative invariants. Note that this constructor deliberately does not check the length of id: RiffReader is the only production path that creates RiffChunk instances and always passes a four-character string, and leaving the length unconstrained keeps test fixtures free to exercise degenerate IDs.
      Throws:
      NullPointerException - if id is null
      IllegalArgumentException - if size or dataStartOffset is negative
  • Method Details

    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with '=='.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • id

      public String id()
      Returns the value of the id record component.
      Returns:
      the value of the id record component
    • size

      public long size()
      Returns the value of the size record component.
      Returns:
      the value of the size record component
    • dataStartOffset

      public long dataStartOffset()
      Returns the value of the dataStartOffset record component.
      Returns:
      the value of the dataStartOffset record component