-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathGetImageIcon.java
More file actions
56 lines (49 loc) · 1.63 KB
/
GetImageIcon.java
File metadata and controls
56 lines (49 loc) · 1.63 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
import javax.swing.ImageIcon;
import java.net.URL;
import java.net.URLConnection;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.awt.MediaTracker;
public class GetImageIcon
{
public static void main (String url[])
{
try
{
URL u = new URL (url[0]);
URLConnection uc = u.openConnection();
uc.connect();
/*
** see if this is HTTP and see if there is a redirection.
*/
if (uc instanceof HttpURLConnection)
{
HttpURLConnection huc = (HttpURLConnection) uc;
System.out.println (huc.getResponseCode());
if (301 == huc.getResponseCode() ||
302 == huc.getResponseCode())
{
System.out.println (huc.getHeaderField ("Location"));
u = new URL (u, huc.getHeaderField ("Location"));
huc = (HttpURLConnection) u.openConnection();
huc.connect();
System.out.println (huc.getResponseCode());
if (200 != huc.getResponseCode())
{
System.out.println ("crapped out");
return;
}
}
}
ImageIcon imageIcon = new ImageIcon (u);
if (imageIcon.getImageLoadStatus() != MediaTracker.COMPLETE)
{
System.out.println ("Failed to load: " + imageIcon);
}
}
catch (Exception e)
{
System.out.println (e);
}
}
}