01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: /**
18: * @author Igor V. Stolyarov
19: * @version $Revision$
20: */package org.apache.harmony.awt.gl.image;
21:
22: import java.io.BufferedInputStream;
23: import java.io.IOException;
24: import java.io.InputStream;
25: import java.net.URL;
26: import java.net.URLConnection;
27: import java.security.Permission;
28:
29: public class URLDecodingImageSource extends DecodingImageSource {
30:
31: URL url;
32:
33: public URLDecodingImageSource(URL url) {
34: SecurityManager security = System.getSecurityManager();
35: if (security != null) {
36: security.checkConnect(url.getHost(), url.getPort());
37: try {
38: Permission p = url.openConnection().getPermission();
39: security.checkPermission(p);
40: } catch (IOException e) {
41: }
42: }
43: this .url = url;
44: }
45:
46: @Override
47: protected boolean checkConnection() {
48: SecurityManager security = System.getSecurityManager();
49: if (security != null) {
50: try {
51: security.checkConnect(url.getHost(), url.getPort());
52: return true;
53: } catch (SecurityException e) {
54: return false;
55: }
56: }
57: return true;
58: }
59:
60: @Override
61: protected InputStream getInputStream() {
62: try {
63: URLConnection uc = url.openConnection();
64: return new BufferedInputStream(uc.getInputStream());
65: } catch (IOException e) {
66: return null;
67: }
68: }
69:
70: }
|