< prev index next >

src/java.desktop/share/classes/sun/awt/image/URLImageSource.java

Print this page




  29 import java.io.IOException;
  30 import java.net.HttpURLConnection;
  31 import java.net.URL;
  32 import java.net.URLConnection;
  33 import java.net.MalformedURLException;
  34 import sun.net.util.URLUtil;
  35 
  36 public class URLImageSource extends InputStreamImageSource {
  37     URL url;
  38     URLConnection conn;
  39     String actualHost;
  40     int actualPort;
  41 
  42     public URLImageSource(URL u) {
  43         SecurityManager sm = System.getSecurityManager();
  44         if (sm != null) {
  45             try {
  46                 java.security.Permission perm =
  47                       URLUtil.getConnectPermission(u);
  48                 if (perm != null) {
  49                     try {
  50                         sm.checkPermission(perm);
  51                     } catch (SecurityException se) {
  52                         // fallback to checkRead/checkConnect for pre 1.2
  53                         // security managers
  54                         if ((perm instanceof java.io.FilePermission) &&
  55                                 perm.getActions().indexOf("read") != -1) {
  56                             sm.checkRead(perm.getName());
  57                         } else if ((perm instanceof
  58                                 java.net.SocketPermission) &&
  59                                 perm.getActions().indexOf("connect") != -1) {
  60                             sm.checkConnect(u.getHost(), u.getPort());
  61                         } else {
  62                             throw se;
  63                         }
  64                     }
  65                 }
  66             } catch (java.io.IOException ioe) {
  67                     sm.checkConnect(u.getHost(), u.getPort());
  68             }
  69         }
  70         this.url = u;
  71 
  72     }
  73 
  74     public URLImageSource(String href) throws MalformedURLException {
  75         this(new URL(null, href));
  76     }
  77 
  78     public URLImageSource(URL u, URLConnection uc) {
  79         this(u);
  80         conn = uc;
  81     }
  82 
  83     public URLImageSource(URLConnection uc) {
  84         this(uc.getURL(), uc);




  29 import java.io.IOException;
  30 import java.net.HttpURLConnection;
  31 import java.net.URL;
  32 import java.net.URLConnection;
  33 import java.net.MalformedURLException;
  34 import sun.net.util.URLUtil;
  35 
  36 public class URLImageSource extends InputStreamImageSource {
  37     URL url;
  38     URLConnection conn;
  39     String actualHost;
  40     int actualPort;
  41 
  42     public URLImageSource(URL u) {
  43         SecurityManager sm = System.getSecurityManager();
  44         if (sm != null) {
  45             try {
  46                 java.security.Permission perm =
  47                       URLUtil.getConnectPermission(u);
  48                 if (perm != null) {

  49                     sm.checkPermission(perm);














  50                 }
  51             } catch (java.io.IOException ioe) {
  52                 sm.checkConnect(u.getHost(), u.getPort());
  53             }
  54         }
  55         this.url = u;
  56 
  57     }
  58 
  59     public URLImageSource(String href) throws MalformedURLException {
  60         this(new URL(null, href));
  61     }
  62 
  63     public URLImageSource(URL u, URLConnection uc) {
  64         this(u);
  65         conn = uc;
  66     }
  67 
  68     public URLImageSource(URLConnection uc) {
  69         this(uc.getURL(), uc);


< prev index next >