FlacMetadataReader { public static FlacStreamMetadata.SeekTable readSeekTableMetadataBlock(ParsableByteArray data) { data.skipBytes(1); int length = data.readUnsignedInt24(); long seekTableEndPosition = data.getPosition() + length; int seekPointCount = length / SEEK_POINT_SIZE; long[] pointSampleNumbers = new long[seekPointCount]; long[] pointOffsets = new long[seekPointCount]; for (int i = 0; i < seekPointCount; i++) { long sampleNumber = data.readLong(); if (sampleNumber == -1) { pointSampleNumbers = Arrays.copyOf(pointSampleNumbers, i); pointOffsets = Arrays.copyOf(pointOffsets, i); break; } pointSampleNumbers[i] = sampleNumber; pointOffsets[i] = data.readLong(); data.skipBytes(2); } data.skipBytes((int) (seekTableEndPosition - data.getPosition())); return new FlacStreamMetadata.SeekTable(pointSampleNumbers, pointOffsets); } private  FlacMetadataReader(); @Nullable static Metadata peekId3Metadata(ExtractorInput input, boolean parseData); static boolean checkAndPeekStreamMarker(ExtractorInput input); @Nullable static Metadata readId3Metadata(ExtractorInput input, boolean parseData); static void readStreamMarker(ExtractorInput input); static boolean readMetadataBlock(
      ExtractorInput input, FlacStreamMetadataHolder metadataHolder); static FlacStreamMetadata.SeekTable readSeekTableMetadataBlock(ParsableByteArray data); static int getFrameStartMarker(ExtractorInput input);  }
@Test public void readSeekTableMetadataBlock_updatesPosition() throws Exception { ExtractorInput input = buildExtractorInput("flac/bear.flac"); input.skipFully(FlacConstants.STREAM_MARKER_SIZE + FlacConstants.STREAM_INFO_BLOCK_SIZE); int seekTableBlockSize = 598; ParsableByteArray scratch = new ParsableByteArray(seekTableBlockSize); input.read(scratch.data, 0, seekTableBlockSize); FlacMetadataReader.readSeekTableMetadataBlock(scratch); assertThat(scratch.getPosition()).isEqualTo(seekTableBlockSize); }
@Test public void readSeekTableMetadataBlock_returnsCorrectSeekPoints() throws Exception { ExtractorInput input = buildExtractorInput("flac/bear.flac"); input.skipFully(FlacConstants.STREAM_MARKER_SIZE + FlacConstants.STREAM_INFO_BLOCK_SIZE); int seekTableBlockSize = 598; ParsableByteArray scratch = new ParsableByteArray(seekTableBlockSize); input.read(scratch.data, 0, seekTableBlockSize); FlacStreamMetadata.SeekTable seekTable = FlacMetadataReader.readSeekTableMetadataBlock(scratch); assertThat(seekTable.pointOffsets[0]).isEqualTo(0); assertThat(seekTable.pointSampleNumbers[0]).isEqualTo(0); assertThat(seekTable.pointOffsets[31]).isEqualTo(160602); assertThat(seekTable.pointSampleNumbers[31]).isEqualTo(126976); }
@Test public void readSeekTableMetadataBlock_ignoresPlaceholders() throws IOException { byte[] fileData = TestUtil.getByteArray(ApplicationProvider.getApplicationContext(), "flac/bear.flac"); ParsableByteArray scratch = new ParsableByteArray(fileData); scratch.skipBytes(FlacConstants.STREAM_MARKER_SIZE + FlacConstants.STREAM_INFO_BLOCK_SIZE); FlacStreamMetadata.SeekTable seekTable = FlacMetadataReader.readSeekTableMetadataBlock(scratch); assertThat(seekTable.pointSampleNumbers).hasLength(32); }