home *** CD-ROM | disk | FTP | other *** search
- package sun.awt.image;
-
- import java.io.IOException;
- import java.io.InputStream;
- import java.net.MalformedURLException;
- import java.net.URL;
- import java.net.URLConnection;
-
- public class URLImageSource extends InputStreamImageSource {
- URL url;
- URLConnection conn;
- String actualHost;
- int actualPort;
-
- public URLImageSource(URL u) {
- SecurityManager sm = System.getSecurityManager();
- if (sm != null) {
- sm.checkConnect(u.getHost(), u.getPort());
- }
-
- this.url = u;
- }
-
- public URLImageSource(String href) throws MalformedURLException {
- this(new URL((URL)null, href));
- }
-
- public URLImageSource(URL u, URLConnection uc) {
- this(u);
- this.conn = uc;
- }
-
- public URLImageSource(URLConnection uc) {
- this(uc.getURL(), uc);
- }
-
- final boolean checkSecurity(Object context, boolean quiet) {
- if (this.actualHost != null) {
- try {
- System.getSecurityManager().checkConnect(this.actualHost, this.actualPort, context);
- } catch (SecurityException e) {
- if (!quiet) {
- throw e;
- }
-
- return false;
- }
- }
-
- return true;
- }
-
- private synchronized URLConnection getConnection() throws IOException {
- URLConnection c;
- if (this.conn != null) {
- c = this.conn;
- this.conn = null;
- } else {
- c = this.url.openConnection();
- }
-
- return c;
- }
-
- protected ImageDecoder getDecoder() {
- InputStream is = null;
- String type = null;
-
- try {
- URLConnection c = this.getConnection();
- is = c.getInputStream();
- type = c.getContentType();
- URL u = c.getURL();
- if (u != this.url && (u.getHost() != this.url.getHost() || u.getPort() != this.url.getPort())) {
- if (this.actualHost != null && (this.actualHost != u.getHost() || this.actualPort != u.getPort())) {
- throw new SecurityException("image moved!");
- }
-
- this.actualHost = u.getHost();
- this.actualPort = u.getPort();
- }
- } catch (IOException var6) {
- if (is != null) {
- try {
- is.close();
- } catch (IOException var5) {
- }
- }
-
- return null;
- }
-
- ImageDecoder id = ((InputStreamImageSource)this).decoderForType(is, type);
- if (id == null) {
- id = ((InputStreamImageSource)this).getDecoder(is);
- }
-
- return id;
- }
- }
-