1/*
2 *  Licensed to the Apache Software Foundation (ASF) under one or more
3 *  contributor license agreements.  See the NOTICE file distributed with
4 *  this work for additional information regarding copyright ownership.
5 *  The ASF licenses this file to You under the Apache License, Version 2.0
6 *  (the "License"); you may not use this file except in compliance with
7 *  the License.  You may obtain a copy of the License at
8 *
9 *     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 */
21/*
22 * Created on 10.02.2005
23 *
24 */
25package org.apache.harmony.awt.gl.image;
26
27import java.io.BufferedInputStream;
28import java.io.IOException;
29import java.io.InputStream;
30import java.net.URL;
31import java.net.URLConnection;
32import java.security.Permission;
33
34public class URLDecodingImageSource extends DecodingImageSource {
35
36    URL url;
37
38    public URLDecodingImageSource(URL url){
39        SecurityManager security = System.getSecurityManager();
40        if (security != null) {
41            security.checkConnect(url.getHost(), url.getPort());
42            try {
43                Permission p = url.openConnection().getPermission();
44                security.checkPermission(p);
45            } catch (IOException e) {
46            }
47        }
48        this.url = url;
49    }
50
51    @Override
52    protected boolean checkConnection() {
53        SecurityManager security = System.getSecurityManager();
54        if (security != null) {
55            try {
56                security.checkConnect(url.getHost(), url.getPort());
57                return true;
58            } catch (SecurityException e) {
59                return false;
60            }
61        }
62        return true;
63    }
64
65    @Override
66    protected InputStream getInputStream() {
67        try{
68            URLConnection uc = url.openConnection();
69            // BEGIN android-modified
70            return new BufferedInputStream(uc.getInputStream(), 8192);
71            // END android-modified
72        }catch(IOException e){
73            return null;
74        }
75    }
76
77}
78