-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathHeaderViewer.java
More file actions
39 lines (37 loc) · 1.25 KB
/
HeaderViewer.java
File metadata and controls
39 lines (37 loc) · 1.25 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
import java.io.*;
import java.net.*;
import java.util.*;
public class HeaderViewer {
public static void main(String[] args) {
for (int i = 0; i < args.length; i++) {
try {
URL u = new URL(args[0]);
URLConnection uc = u.openConnection();
System.out.println("Content-type: " + uc.getContentType());
if (uc.getContentEncoding() != null) {
System.out.println("Content-encoding: "
+ uc.getContentEncoding());
}
if (uc.getDate() != 0) {
System.out.println("Date: " + new Date(uc.getDate()));
}
if (uc.getLastModified() != 0) {
System.out.println("Last modified: "
+ new Date(uc.getLastModified()));
}
if (uc.getExpiration() != 0) {
System.out.println("Expiration date: "
+ new Date(uc.getExpiration()));
}
if (uc.getContentLength() != -1) {
System.out.println("Content-length: " + uc.getContentLength());
}
} catch (MalformedURLException ex) {
System.err.println(args[i] + " is not a URL I understand");
} catch (IOException ex) {
System.err.println(ex);
}
System.out.println();
}
}
}