| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
package com.drew.tools; |
| 23 |
|
| 24 |
import com.drew.imaging.ImageMetadataReader; |
| 25 |
import com.drew.imaging.ImageProcessingException; |
| 26 |
import com.drew.imaging.jpeg.JpegProcessingException; |
| 27 |
import com.drew.metadata.Directory; |
| 28 |
import com.drew.metadata.Metadata; |
| 29 |
import com.drew.metadata.Tag; |
| 30 |
|
| 31 |
import java.io.IOException; |
| 32 |
import java.io.InputStream; |
| 33 |
import java.net.URL; |
| 34 |
import java.net.URLConnection; |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
public class ProcessUrlUtility |
| 42 |
{ |
| 43 |
public static void main(String[] args) throws IOException, JpegProcessingException |
| 44 |
{ |
| 45 |
if (args.length == 0) { |
| 46 |
System.err.println("Expects one or more URLs as arguments."); |
| 47 |
System.exit(1); |
| 48 |
} |
| 49 |
|
| 50 |
for (String url : args) |
| 51 |
processUrl(new URL(url)); |
| 52 |
|
| 53 |
System.out.println("Completed."); |
| 54 |
} |
| 55 |
|
| 56 |
private static void processUrl(URL url) throws IOException |
| 57 |
{ |
| 58 |
URLConnection con = url.openConnection(); |
| 59 |
|
| 60 |
|
| 61 |
InputStream in = con.getInputStream(); |
| 62 |
|
| 63 |
|
| 64 |
final Metadata metadata; |
| 65 |
try { |
| 66 |
metadata = ImageMetadataReader.readMetadata(in); |
| 67 |
} catch (ImageProcessingException e) { |
| 68 |
|
| 69 |
|
| 70 |
System.err.printf("%s: %s [Error Extracting Metadata]%n\t%s%n", e.getClass().getName(), url, e.getMessage()); return; |
| 71 |
} catch (Throwable t) { |
| 72 |
|
| 73 |
System.err.printf("%s: %s [Error Extracting Metadata]%n", t.getClass().getName(), url); |
| 74 |
t.printStackTrace(System.err); |
| 75 |
return; |
| 76 |
} |
| 77 |
|
| 78 |
if (metadata.hasErrors()) { |
| 79 |
System.err.println(url); |
| 80 |
for (Directory directory : metadata.getDirectories()) { |
| 81 |
if (!directory.hasErrors()) |
| 82 |
continue; |
| 83 |
for (String error : directory.getErrors()) { |
| 84 |
System.err.printf("\t[%s] %s%n", directory.getName(), error); |
| 85 |
} |
| 86 |
} |
| 87 |
} |
| 88 |
|
| 89 |
|
| 90 |
for (Directory directory : metadata.getDirectories()) { |
| 91 |
for (Tag tag : directory.getTags()) { |
| 92 |
String tagName = tag.getTagName(); |
| 93 |
String directoryName = directory.getName(); |
| 94 |
String description = tag.getDescription(); |
| 95 |
|
| 96 |
|
| 97 |
if (description != null && description.length() > 1024) { |
| 98 |
description = description.substring(0, 1024) + "..."; |
| 99 |
} |
| 100 |
|
| 101 |
System.out.printf("[%s] %s = %s%n", directoryName, tagName, description); |
| 102 |
} |
| 103 |
} |
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
} |
| 108 |
} |