use of de.danoeh.antennapod.parser.media.id3.model.FrameHeader in project AntennaPod by AntennaPod.
the class ChapterReaderTest method testReadChapterWithTitle.
@Test
public void testReadChapterWithTitle() throws IOException, ID3ReaderException {
byte[] title = { ID3Reader.ENCODING_ISO, // Title
'H', // Title
'e', // Title
'l', // Title
'l', // Title
'o', // Null-terminated
0 };
byte[] chapterData = Id3ReaderTest.concat(CHAPTER_WITHOUT_SUBFRAME, Id3ReaderTest.generateFrameHeader(ChapterReader.FRAME_ID_TITLE, title.length), title);
FrameHeader header = new FrameHeader(ChapterReader.FRAME_ID_CHAPTER, chapterData.length, (short) 0);
CountingInputStream inputStream = new CountingInputStream(new ByteArrayInputStream(chapterData));
ChapterReader reader = new ChapterReader(inputStream);
Chapter chapter = reader.readChapter(header);
assertEquals(CHAPTER_WITHOUT_SUBFRAME_START_TIME, chapter.getStart());
assertEquals("Hello", chapter.getTitle());
}
use of de.danoeh.antennapod.parser.media.id3.model.FrameHeader in project AntennaPod by AntennaPod.
the class ChapterReaderTest method testReadTitleWithGarbage.
@Test
public void testReadTitleWithGarbage() throws IOException, ID3ReaderException {
byte[] titleSubframeContent = { ID3Reader.ENCODING_ISO, // Title
'A', // Null-terminated
0, // Garbage, should be ignored
42, // Garbage, should be ignored
42, // Garbage, should be ignored
42, // Garbage, should be ignored
42 };
FrameHeader header = new FrameHeader(ChapterReader.FRAME_ID_TITLE, titleSubframeContent.length, (short) 0);
CountingInputStream inputStream = new CountingInputStream(new ByteArrayInputStream(titleSubframeContent));
ChapterReader reader = new ChapterReader(inputStream);
Chapter chapter = new ID3Chapter("", 0);
reader.readChapterSubFrame(header, chapter);
assertEquals("A", chapter.getTitle());
// Should skip the garbage and point to the next frame
assertEquals(titleSubframeContent.length, reader.getPosition());
}
use of de.danoeh.antennapod.parser.media.id3.model.FrameHeader in project AntennaPod by AntennaPod.
the class ChapterReaderTest method testReadChapterWithoutSubframes.
@Test
public void testReadChapterWithoutSubframes() throws IOException, ID3ReaderException {
FrameHeader header = new FrameHeader(ChapterReader.FRAME_ID_CHAPTER, CHAPTER_WITHOUT_SUBFRAME.length, (short) 0);
CountingInputStream inputStream = new CountingInputStream(new ByteArrayInputStream(CHAPTER_WITHOUT_SUBFRAME));
Chapter chapter = new ChapterReader(inputStream).readChapter(header);
assertEquals(CHAPTER_WITHOUT_SUBFRAME_START_TIME, chapter.getStart());
}
use of de.danoeh.antennapod.parser.media.id3.model.FrameHeader in project AntennaPod by AntennaPod.
the class ChapterReader method readChapter.
public Chapter readChapter(@NonNull FrameHeader frameHeader) throws IOException, ID3ReaderException {
int chapterStartedPosition = getPosition();
String elementId = readIsoStringNullTerminated(100);
long startTime = readInt();
// Ignore end time, start offset, end offset
skipBytes(12);
ID3Chapter chapter = new ID3Chapter(elementId, startTime);
// Read sub-frames
while (getPosition() < chapterStartedPosition + frameHeader.getSize()) {
FrameHeader subFrameHeader = readFrameHeader();
readChapterSubFrame(subFrameHeader, chapter);
}
return chapter;
}
use of de.danoeh.antennapod.parser.media.id3.model.FrameHeader in project AntennaPod by AntennaPod.
the class ID3Reader method readInputStream.
public void readInputStream() throws IOException, ID3ReaderException {
tagHeader = readTagHeader();
int tagContentStartPosition = getPosition();
while (getPosition() < tagContentStartPosition + tagHeader.getSize()) {
FrameHeader frameHeader = readFrameHeader();
if (frameHeader.getId().charAt(0) < '0' || frameHeader.getId().charAt(0) > 'z') {
Log.d(TAG, "Stopping because of invalid frame: " + frameHeader.toString());
return;
}
readFrame(frameHeader);
}
}
Aggregations