-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathHiddenSecrets.java
More file actions
85 lines (77 loc) · 3.07 KB
/
HiddenSecrets.java
File metadata and controls
85 lines (77 loc) · 3.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package src;
import com.drew.imaging.ImageProcessingException;
import com.drew.metadata.Metadata;
import com.drew.metadata.Directory;
import com.drew.metadata.Tag;
import com.drew.imaging.ImageMetadataReader;
import java.io.*;
import java.net.URL;
import java.nio.file.Paths;
import java.util.Scanner;
public class HiddenSecrets {
public static void getHiddenSecrets(File file) {
try {
Metadata metadata = ImageMetadataReader.readMetadata(
new FileInputStream(file)
);
for (Directory directory : metadata.getDirectories()) {
for (Tag tag : directory.getTags()) {
System.out.format("[%s] - %s = %s%n",
directory.getName(), tag.getTagName(), tag.getDescription());
}
if (directory.hasErrors()) {
for (String error : directory.getErrors()) {
System.err.format("ERROR: %s%n", error);
}
}
}
} catch (FileNotFoundException fnfe) {
System.out.println("That file does not exist.");
} catch (IOException ioe) {
System.out.println("Problem reading from file stream.");
} catch (ImageProcessingException ipe) {
System.out.println("Failed to process the image meta-data");
}
}
public static void getHiddenSecretsFromURL(URL url) {
try {
Metadata metadata = ImageMetadataReader.readMetadata(
url.openStream()
);
for (Directory directory : metadata.getDirectories()) {
for (Tag tag : directory.getTags()) {
System.out.format("[%s] - %s = %s%n",
directory.getName(), tag.getTagName(), tag.getDescription());
}
if (directory.hasErrors()) {
for (String error : directory.getErrors()) {
System.err.format("ERROR: %s%n", error);
}
}
}
} catch (ImageProcessingException e) {
System.out.println("Failed to process the image meta-data.");
throw new RuntimeException(e);
} catch (IOException e) {
System.out.println("Problem reading from URL.");
throw new RuntimeException(e);
}
}
public static void main(String[] args) throws IOException {
while (true) {
System.out.print("File path or URL to image: ");
Scanner scanner = new Scanner(System.in);
String location = scanner.nextLine().trim();
// add a lazy exit clause
if (location.equalsIgnoreCase("end") || location.equalsIgnoreCase("exit")) {
return;
}
if (location.startsWith("https://") || location.startsWith("http://")) {
getHiddenSecretsFromURL(new URL(location));
} else {
getHiddenSecrets(Paths.get(location).toFile());
}
System.out.println();
}
}
}