Debian Codegraph @

src/com/drew/imaging/tiff/TiffMetadataReader.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.tiff;
22
23 import com.drew.lang.RandomAccessFileReader;
24 import com.drew.lang.RandomAccessReader;
25 import com.drew.lang.RandomAccessStreamReader;
26 import com.drew.lang.annotations.NotNull;
27 import com.drew.metadata.Metadata;
28 import com.drew.metadata.exif.ExifTiffHandler;
29 import com.drew.metadata.file.FileSystemMetadataReader;
30
31 import java.io.*;
32
33 /**
34 * Obtains all available metadata from TIFF formatted files. Note that TIFF files include many digital camera RAW
35 * formats, including Canon (CRW, CR2), Nikon (NEF), Olympus (ORF) and Panasonic (RW2).
36 *
37 * @author Darren Salomons
38 * @author Drew Noakes https://drewnoakes.com
39 */
40 public class TiffMetadataReader
41 {
42 @NotNull
43 public static Metadata readMetadata(@NotNull File file) throws IOException, TiffProcessingException
44 {
45 RandomAccessFile randomAccessFile = new RandomAccessFile(file, "r");
46 Metadata metadata;
47 try {
48 metadata = readMetadata(new RandomAccessFileReader(randomAccessFile));
49 } finally {
50 randomAccessFile.close();
51 }
52 new FileSystemMetadataReader().read(file, metadata);
53 return metadata;
54 }
55
56 @NotNull
57 public static Metadata readMetadata(@NotNull InputStream inputStream) throws IOException, TiffProcessingException
58 {
59 // TIFF processing requires random access, as directories can be scattered throughout the byte sequence.
60 // InputStream does not support seeking backwards, so we wrap it with RandomAccessStreamReader, which
61 // buffers data from the stream as we seek forward.
62
63 return readMetadata(new RandomAccessStreamReader(inputStream));
64 }
65
66 @NotNull
67 public static Metadata readMetadata(@NotNull RandomAccessReader reader) throws IOException, TiffProcessingException
68 {
69 Metadata metadata = new Metadata();
70 ExifTiffHandler handler = new ExifTiffHandler(metadata, null, 0);
71 new TiffReader().processTiff(reader, handler, 0);
72 return metadata;
73 }
74 }