* This constructor does not check the validity of the seek points, namely the ordering * of seek point offsets, so calling {@link#checkValues()} on the freshly constructed object * can fail. However, this does guarantee that every point's frameSamples field is a uint16. *
* * @param b the metadata block's payload data to parse (not {@code null}) * @throws NullPointerException if the array is {@code null} * @throws IllegalArgumentException if the array length * is not a multiple of 18 (size of each seek point) */ public SeekTable(byte[] b) { this(); Objects.requireNonNull(b); if (b.length % 18 != 0) throw new IllegalArgumentException("Data contains a partial seek point"); try { DataInput in = new DataInputStream(new ByteArrayInputStream(b)); for (int i = 0; i < b.length; i += 18) { SeekPoint p = new SeekPoint(); p.sampleOffset = in.readLong(); p.fileOffset = in.readLong(); p.frameSamples = in.readUnsignedShort(); points.add(p); } // Skip closing the in-memory streams } catch (IOException e) { throw new AssertionError(e); } } /*---- Methods ----*/ /** * Checks the state of this object and returns silently if all these criteria pass: ** A seek point with data (sampleOffset = x, fileOffset = y, frameSamples = z) means * that at byte position (y + (byte offset of foremost audio frame)) in the file, * a FLAC frame begins (with the sync sequence), that frame has sample offset x * (where sample 0 is defined as the start of the audio stream), * and the frame contains z samples per channel. * * @see SeekTable */ public static final class SeekPoint { /** * The sample offset in the audio stream, a uint64 value. * A value of -1 (i.e. 0xFFF...FFF) means this is a placeholder point. */ public long sampleOffset; /** * The byte offset relative to the start of the foremost frame, a uint64 value. * If sampleOffset is -1, then this value is ignored. */ public long fileOffset; /** * The number of audio samples in the target block/frame, a uint16 value. * If sampleOffset is -1, then this value is ignored. */ public int frameSamples; } }