Fix vorbis chapter parsing

This commit is contained in:
ByteHamster 2022-01-22 17:03:21 +01:00
parent 49b6386a6d
commit 3b9dfb3c76
1 changed files with 4 additions and 5 deletions

View File

@ -41,7 +41,7 @@ public abstract class VorbisCommentReader {
public void readInputStream(InputStream input) throws VorbisCommentReaderException { public void readInputStream(InputStream input) throws VorbisCommentReaderException {
try { try {
findIdentificationHeader(input); skipIdentificationHeader(input);
onVorbisCommentFound(); onVorbisCommentFound();
findOggPage(input); findOggPage(input);
findCommentHeader(input); findCommentHeader(input);
@ -101,21 +101,20 @@ public abstract class VorbisCommentReader {
/** /**
* Looks for an identification header in the first page of the file. If an * Looks for an identification header in the first page of the file. If an
* identification header is found, it will be skipped completely and the * identification header is found, it will be skipped completely
* method will return true, otherwise false.
*/ */
private void findIdentificationHeader(InputStream input) throws IOException { private void skipIdentificationHeader(InputStream input) throws IOException {
byte[] buffer = new byte[FIRST_OPUS_PAGE_LENGTH]; byte[] buffer = new byte[FIRST_OPUS_PAGE_LENGTH];
IOUtils.readFully(input, buffer); IOUtils.readFully(input, buffer);
final byte[] oggIdentificationHeader = new byte[]{ PACKET_TYPE_IDENTIFICATION, 'v', 'o', 'r', 'b', 'i', 's' }; final byte[] oggIdentificationHeader = new byte[]{ PACKET_TYPE_IDENTIFICATION, 'v', 'o', 'r', 'b', 'i', 's' };
for (int i = 6; i < buffer.length; i++) { for (int i = 6; i < buffer.length; i++) {
if (bufferMatches(buffer, oggIdentificationHeader, i)) { if (bufferMatches(buffer, oggIdentificationHeader, i)) {
IOUtils.skip(input, FIRST_OGG_PAGE_LENGTH - FIRST_OPUS_PAGE_LENGTH); IOUtils.skip(input, FIRST_OGG_PAGE_LENGTH - FIRST_OPUS_PAGE_LENGTH);
return;
} else if (bufferMatches(buffer, "OpusHead".getBytes(), i)) { } else if (bufferMatches(buffer, "OpusHead".getBytes(), i)) {
return; return;
} }
} }
throw new IOException("No identification header found");
} }
private void findCommentHeader(InputStream input) throws IOException { private void findCommentHeader(InputStream input) throws IOException {