1 |
| package photospace.meta; |
2 |
| |
3 |
| import java.io.*; |
4 |
| import java.util.*; |
5 |
| import org.apache.commons.logging.*; |
6 |
| import com.drew.imaging.jpeg.*; |
7 |
| import com.drew.metadata.*; |
8 |
| |
9 |
| public class Reader |
10 |
| { |
11 |
| private static final Log log = LogFactory.getLog(Reader.class); |
12 |
| |
13 |
| private static Metadata metadata; |
14 |
| |
15 |
0
| public Reader(String filename) throws IOException, JpegProcessingException
|
16 |
| { |
17 |
0
| InputStream in = getClass().getClassLoader().getResource(filename).openStream();
|
18 |
0
| metadata = JpegMetadataReader.readMetadata(in);
|
19 |
| } |
20 |
| |
21 |
0
| public Reader(File path) throws IOException, JpegProcessingException
|
22 |
| { |
23 |
0
| metadata = JpegMetadataReader.readMetadata(path);
|
24 |
| } |
25 |
| |
26 |
0
| public String getDump() throws Exception
|
27 |
| { |
28 |
0
| StringBuffer data = new StringBuffer();
|
29 |
0
| Directory directory = null;
|
30 |
0
| for (Iterator directories = metadata.getDirectoryIterator(); directories.hasNext();)
|
31 |
| { |
32 |
0
| directory = (Directory) directories.next();
|
33 |
0
| data.append("\n\nDIRECTORY: " + directory.getName());
|
34 |
0
| for (Iterator tags = directory.getTagIterator(); tags.hasNext();)
|
35 |
| { |
36 |
0
| Tag tag = (Tag) tags.next();
|
37 |
| |
38 |
0
| data.append("\n" + tag.getTagName() + ": " + tag.getDescription());
|
39 |
| } |
40 |
| } |
41 |
0
| return data.toString();
|
42 |
| } |
43 |
| |
44 |
0
| public static void main(String args []) throws Exception
|
45 |
| { |
46 |
0
| for (int i = 0; i < args.length; i++)
|
47 |
| { |
48 |
0
| System.out.println("\n\nReading [" + args[i] + "]:");
|
49 |
0
| if (new File(args[i]).exists()) System.out.println(new Reader(new File(args[i])).getDump());
|
50 |
0
| else System.out.println(new Reader(args[i]).getDump());
|
51 |
| } |
52 |
| } |
53 |
| |
54 |
| } |