File fragFile = File.createTempFile("SampleListTest", "testFragmented");
FileOutputStream fos = new FileOutputStream(fragFile);
Movie m = MovieCreator.build(Channels.newChannel(getClass().getResourceAsStream("/Beethoven - Bagatelle op.119 no.11 i.m4a")));
IsoFile orig = new IsoFile(Channels.newChannel(getClass().getResourceAsStream("/Beethoven - Bagatelle op.119 no.11 i.m4a")));
SampleList slOrig = new SampleList(orig.getMovieBox().getBoxes(TrackBox.class).get(0));
FragmentedMp4Builder fragmentedMp4Builder = new FragmentedMp4Builder();
fragmentedMp4Builder.setIntersectionFinder(new TwoSecondIntersectionFinder());
IsoFile isoFile = fragmentedMp4Builder.build(m);
isoFile.getBox(fos.getChannel());
fos.close();
IsoFile fragmented = new IsoFile(new FileInputStream(fragFile).getChannel());
SampleList slFrag = new SampleList(fragmented.getMovieBox().getBoxes(TrackBox.class).get(0));
Assert.assertEquals(slOrig.size(), slFrag.size());
Iterator<ByteBuffer> origBBIt = slOrig.iterator();
Iterator<ByteBuffer> fragBBIt = slFrag.iterator();
while (origBBIt.hasNext() && fragBBIt.hasNext()) {
ByteBuffer origSample = origBBIt.next();
ByteBuffer fragSample = fragBBIt.next();
origSample.reset();
fragSample.reset();
while (origSample.remaining() > 0 && fragSample.remaining() > 0) {
Assert.assertEquals((byte) origSample.get(), (byte) fragSample.get());
}
Assert.assertTrue(origSample.remaining() == 0);
Assert.assertTrue(fragSample.remaining() == 0);
}