@Test
public void testReadPacketsWithEmptyPage() throws Exception {

  byte[] firstPacket = TestUtil.buildTestData(8, random);
  byte[] secondPacket = TestUtil.buildTestData(272, random);
  byte[] thirdPacket = TestUtil.buildTestData(256, random);
  byte[] fourthPacket = TestUtil.buildTestData(271, random);
  FakeExtractorInput input =
      OggTestData.createInput(
          TestUtil.joinByteArrays(
              // First page with a single packet.
              OggTestData.buildOggHeader(0x02, 0, 1000, 0x01),
              TestUtil.createByteArray(0x08), // Laces
              firstPacket,
              // Second page with a single packet.
              OggTestData.buildOggHeader(0x00, 16, 1001, 0x02),
              TestUtil.createByteArray(0xFF, 0x11), // Laces
              secondPacket,
              // Third page with zero packets.
              OggTestData.buildOggHeader(0x00, 16, 1002, 0x00),
              // Fourth page with two packets.
              OggTestData.buildOggHeader(0x04, 128, 1003, 0x04),
              TestUtil.createByteArray(0xFF, 0x01, 0xFF, 0x10), // Laces
              thirdPacket,
              fourthPacket),
          true);
  assertReadPacket(input, firstPacket);
  assertThat((oggPacket.getPageHeader().type & 0x02) == 0x02).isTrue();
  assertThat((oggPacket.getPageHeader().type & 0x04) == 0x04).isFalse();
  assertThat(oggPacket.getPageHeader().type).isEqualTo(0x02);
  assertThat(oggPacket.getPageHeader().headerSize).isEqualTo(27 + 1);
  assertThat(oggPacket.getPageHeader().bodySize).isEqualTo(8);
  assertThat(oggPacket.getPageHeader().revision).isEqualTo(0x00);
  assertThat(oggPacket.getPageHeader().pageSegmentCount).isEqualTo(1);
  assertThat(oggPacket.getPageHeader().pageSequenceNumber).isEqualTo(1000);
  assertThat(oggPacket.getPageHeader().streamSerialNumber).isEqualTo(4096);
  assertThat(oggPacket.getPageHeader().granulePosition).isEqualTo(0);
  assertReadPacket(input, secondPacket);
  assertThat((oggPacket.getPageHeader().type & 0x02) == 0x02).isFalse();
  assertThat((oggPacket.getPageHeader().type & 0x04) == 0x04).isFalse();
  assertThat(oggPacket.getPageHeader().type).isEqualTo(0);
  assertThat(oggPacket.getPageHeader().headerSize).isEqualTo(27 + 2);
  assertThat(oggPacket.getPageHeader().bodySize).isEqualTo(255 + 17);
  assertThat(oggPacket.getPageHeader().pageSegmentCount).isEqualTo(2);
  assertThat(oggPacket.getPageHeader().pageSequenceNumber).isEqualTo(1001);
  assertThat(oggPacket.getPageHeader().granulePosition).isEqualTo(16);
  assertReadPacket(input, thirdPacket);
  assertThat((oggPacket.getPageHeader().type & 0x02) == 0x02).isFalse();
  assertThat((oggPacket.getPageHeader().type & 0x04) == 0x04).isTrue();
  assertThat(oggPacket.getPageHeader().type).isEqualTo(4);
  assertThat(oggPacket.getPageHeader().headerSize).isEqualTo(27 + 4);
  assertThat(oggPacket.getPageHeader().bodySize).isEqualTo(255 + 1 + 255 + 16);
  assertThat(oggPacket.getPageHeader().pageSegmentCount).isEqualTo(4);
  // Page 1002 is empty, so current page is 1003.
  assertThat(oggPacket.getPageHeader().pageSequenceNumber).isEqualTo(1003);
  assertThat(oggPacket.getPageHeader().granulePosition).isEqualTo(128);
  assertReadPacket(input, fourthPacket);
  assertReadEof(input);
}