KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > vfs > impl > URLStreamHandlerProxy


1 /*
2  * Copyright 2002-2005 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.commons.vfs.impl;
17
18 import java.io.IOException JavaDoc;
19 import java.net.MalformedURLException JavaDoc;
20 import java.net.URL JavaDoc;
21 import java.net.URLConnection JavaDoc;
22 import java.net.URLStreamHandler JavaDoc;
23
24 /**
25  * A proxy for URLs that are supported by the standard stream handler factory.
26  *
27  * @author <a HREF="mailto:brian@mmmanager.org">Brian Olsen</a>
28  */

29 class URLStreamHandlerProxy
30     extends URLStreamHandler JavaDoc
31 {
32     protected URLConnection JavaDoc openConnection(final URL JavaDoc url)
33         throws IOException JavaDoc
34     {
35         final URL JavaDoc proxyURL = new URL JavaDoc(url.toExternalForm());
36         return proxyURL.openConnection();
37     }
38
39     protected void parseURL(final URL JavaDoc u,
40                             final String JavaDoc spec,
41                             final int start,
42                             final int limit)
43     {
44         try
45         {
46             final URL JavaDoc url = new URL JavaDoc(u, spec);
47             setURL(u, url.getProtocol(), url.getHost(),
48                 url.getPort(), url.getAuthority(), url.getUserInfo(),
49                 url.getFile(), url.getQuery(), url.getRef());
50         }
51         catch (MalformedURLException JavaDoc mue)
52         {
53             //We retrow this as a simple runtime exception.
54
//It is retrown in URL as a MalformedURLException anyway.
55
throw new RuntimeException JavaDoc(mue.getMessage());
56         }
57     }
58 }
59
Popular Tags