11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package sun.awt.image;
27
28 import java.io.InputStream;
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;
|
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package sun.awt.image;
27
28 import java.io.InputStream;
29 import java.io.IOException;
30 import java.net.HttpURLConnection;
31 import java.net.MalformedURLException;
32 import java.net.SocketPermission;
33 import java.net.URL;
34 import java.net.URLConnection;
35 import java.net.URLPermission;
36
37 import sun.net.util.URLUtil;
38
39 public class URLImageSource extends InputStreamImageSource {
40 URL url;
41 URLConnection conn;
42 String actualHost;
43 int actualPort;
44
45 public URLImageSource(URL u) {
46 SecurityManager sm = System.getSecurityManager();
47 if (sm != null) {
48 try {
49 java.security.Permission perm =
50 URLUtil.getConnectPermission(u);
51 if (perm != null) {
52 try {
53 sm.checkPermission(perm);
54 } catch (SecurityException se) {
55 // fallback to checkRead/checkConnect for pre 1.2
56 // security managers
57 if ((perm instanceof java.io.FilePermission) &&
58 perm.getActions().indexOf("read") != -1) {
59 sm.checkRead(perm.getName());
60 } else if ((perm instanceof
61 java.net.SocketPermission) &&
62 perm.getActions().indexOf("connect") != -1) {
63 sm.checkConnect(u.getHost(), u.getPort());
64 } else if (perm instanceof URLPermission) {
65 sm.checkPermission(
66 new SocketPermission(u.getHost(), "connect"));
67 } else {
68 throw se;
69 }
70 }
71 }
72 } catch (java.io.IOException ioe) {
73 sm.checkConnect(u.getHost(), u.getPort());
74 }
75 }
76 this.url = u;
77
78 }
79
80 public URLImageSource(String href) throws MalformedURLException {
81 this(new URL(null, href));
82 }
83
84 public URLImageSource(URL u, URLConnection uc) {
85 this(u);
86 conn = uc;
|