Debian Codegraph @

src/com/drew/imaging/quicktime/QuickTimeReader.java

raw symbols SCIP
1 /*
2 * Copyright 2002-2019 Drew Noakes and contributors
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 * More information about this project is available at:
17 *
18 * https://drewnoakes.com/code/exif/
19 * https://github.com/drewnoakes/metadata-extractor
20 */
21 package com.drew.imaging.quicktime;
22
23 import com.drew.lang.StreamReader;
24 import com.drew.lang.annotations.NotNull;
25 import com.drew.metadata.mov.QuickTimeContext;
26 import com.drew.metadata.mov.atoms.Atom;
27
28 import java.io.IOException;
29 import java.io.InputStream;
30
31 /**
32 * @author Payton Garland
33 */
34 public class QuickTimeReader
35 {
36 private QuickTimeReader() {}
37
38 public static void extract(@NotNull InputStream inputStream, @NotNull QuickTimeHandler<?> handler)
39 {
40 StreamReader reader = new StreamReader(inputStream);
41 reader.setMotorolaByteOrder(true);
42
43 QuickTimeContext context = new QuickTimeContext();
44
45 processAtoms(reader, -1, handler, context);
46 }
47
48 private static void processAtoms(StreamReader reader, long atomEnd, QuickTimeHandler<?> handler, QuickTimeContext context)
49 {
50 try {
51 while (atomEnd == -1 || reader.getPosition() < atomEnd) {
52
53 Atom atom = new Atom(reader);
54
55 // Determine if fourCC is container/atom and process accordingly.
56 // Unknown atoms will be skipped
57
58 if (atom.size > Integer.MAX_VALUE) {
59 handler.addError("Atom size too large.");
60 break;
61 }
62
63 if (atom.size < 8) {
64 handler.addError("Atom size too small.");
65 break;
66 }
67
68 if (handler.shouldAcceptContainer(atom)) {
69 processAtoms(reader, atom.size + reader.getPosition() - 8, handler.processContainer(atom, context), context);
70 } else if (handler.shouldAcceptAtom(atom)) {
71 handler = handler.processAtom(atom, reader.getBytes((int)atom.size - 8), context);
72 } else if (atom.size > 8) {
73 reader.skip(atom.size - 8);
74 } else if (atom.size == -1) {
75 break;
76 }
77 }
78 } catch (IOException e) {
79 handler.addError(e.getMessage());
80 }
81 }
82 }