@Override public void parse(ReadableByteChannel dataSource, ByteBuffer header, long contentSize, BoxParser boxParser) throws IOException { // Read first 20 bytes to determine whether the file is formatted according to QuickTime File Format. RewindableReadableByteChannel rewindableDataSource = new RewindableReadableByteChannel(dataSource, 20); ByteBuffer bb = ByteBuffer.allocate(20); int bytesRead = rewindableDataSource.read(bb); if (bytesRead == 20) { // If the second and the fifth 32-bit integers encode 'hdlr' and 'mdta' respectively then the MetaBox is // formatted according to QuickTime File Format. // See https://developer.apple.com/library/content/documentation/QuickTime/QTFF/Metadata/Metadata.html bb.position(4); String second4cc = IsoTypeReader.read4cc(bb); bb.position(16); String fifth4cc = IsoTypeReader.read4cc(bb); if ("hdlr".equals(second4cc) && "mdta".equals(fifth4cc)) { quickTimeFormat = true; } } rewindableDataSource.rewind(); if (!quickTimeFormat) { bb = ByteBuffer.allocate(4); rewindableDataSource.read(bb); parseVersionAndFlags((ByteBuffer) bb.rewind()); } int bytesUsed = quickTimeFormat ? 0 : 4; initContainer(rewindableDataSource, contentSize - bytesUsed, boxParser); }
@Override public void parse(ReadableByteChannel dataSource, ByteBuffer header, long contentSize, BoxParser boxParser) throws IOException { // Read first 20 bytes to determine whether the file is formatted according to QuickTime File Format. RewindableReadableByteChannel rewindableDataSource = new RewindableReadableByteChannel(dataSource, 20); ByteBuffer bb = ByteBuffer.allocate(20); int bytesRead = rewindableDataSource.read(bb); if (bytesRead == 20) { // If the second and the fifth 32-bit integers encode 'hdlr' and 'mdta' respectively then the MetaBox is // formatted according to QuickTime File Format. // See https://developer.apple.com/library/content/documentation/QuickTime/QTFF/Metadata/Metadata.html bb.position(4); String second4cc = IsoTypeReader.read4cc(bb); bb.position(16); String fifth4cc = IsoTypeReader.read4cc(bb); if ("hdlr".equals(second4cc) && "mdta".equals(fifth4cc)) { quickTimeFormat = true; } } rewindableDataSource.rewind(); if (!quickTimeFormat) { bb = ByteBuffer.allocate(4); rewindableDataSource.read(bb); parseVersionAndFlags((ByteBuffer) bb.rewind()); } int bytesUsed = quickTimeFormat ? 0 : 4; initContainer(rewindableDataSource, contentSize - bytesUsed, boxParser); }