]> git.uio.no Git - ifi-stolz-refaktor.git/blob - case-study/jdt-after/jar in jar loader/org/eclipse/jdt/internal/jarinjarloader/RsrcURLConnection.java
Case Study: adding data and statistics
[ifi-stolz-refaktor.git] / case-study / jdt-after / jar in jar loader / org / eclipse / jdt / internal / jarinjarloader / RsrcURLConnection.java
1 /*******************************************************************************
2  * Copyright (c) 2008, 2009 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  *     Ferenc Hechler - initial API and implementation
10  *     Ferenc Hechler, ferenc_hechler@users.sourceforge.net - 219530 [jar application] add Jar-in-Jar ClassLoader option
11  *     Ferenc Hechler, ferenc_hechler@users.sourceforge.net - 262746 [jar exporter] Create a builder for jar-in-jar-loader.zip
12  *     Ferenc Hechler, ferenc_hechler@users.sourceforge.net - 262748 [jar exporter] extract constants for string literals in JarRsrcLoader et al.
13  *******************************************************************************/
14 package org.eclipse.jdt.internal.jarinjarloader;
15
16 import java.io.IOException;
17 import java.io.InputStream;
18 import java.net.MalformedURLException;
19 import java.net.URL;
20 import java.net.URLConnection;
21 import java.net.URLDecoder;
22
23
24 /**
25  * This class will be compiled into the binary jar-in-jar-loader.zip. This ZIP is used for the
26  * "Runnable JAR File Exporter"
27  * 
28  * @since 3.5
29  */
30 public class RsrcURLConnection extends URLConnection {
31
32         private ClassLoader classLoader;
33
34         public RsrcURLConnection(URL url, ClassLoader classLoader) {
35                 super(url);
36                 this.classLoader= classLoader;
37         }
38
39         public void connect() throws IOException {
40         }
41
42         public InputStream getInputStream() throws IOException {
43                 String file= URLDecoder.decode(url.getFile(), JIJConstants.UTF8_ENCODING);
44                 InputStream result= classLoader.getResourceAsStream(file);
45                 if (result == null) {
46                         throw new MalformedURLException("Could not open InputStream for URL '" + url + "'"); //$NON-NLS-1$ //$NON-NLS-2$
47                 }
48                 return result;
49         }
50
51
52 }