| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 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 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 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 |
|
| 60 |
|
| 61 |
|
| 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 |
} |