author | Jaroslav Tulach <jaroslav.tulach@apidesign.org> |
Wed, 28 May 2014 09:07:48 +0200 | |
branch | closure |
changeset 1608 | 5186733b7e07 |
parent 1094 | 36961c9a009f |
parent 1411 | 1c76f0f66aeb |
child 1787 | ea12a3bb4b33 |
permissions | -rw-r--r-- |
jaroslav@874 | 1 |
/** |
jaroslav@874 | 2 |
* Back 2 Browser Bytecode Translator |
jaroslav@874 | 3 |
* Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org> |
jaroslav@874 | 4 |
* |
jaroslav@874 | 5 |
* This program is free software: you can redistribute it and/or modify |
jaroslav@874 | 6 |
* it under the terms of the GNU General Public License as published by |
jaroslav@874 | 7 |
* the Free Software Foundation, version 2 of the License. |
jaroslav@874 | 8 |
* |
jaroslav@874 | 9 |
* This program is distributed in the hope that it will be useful, |
jaroslav@874 | 10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
jaroslav@874 | 11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
jaroslav@874 | 12 |
* GNU General Public License for more details. |
jaroslav@874 | 13 |
* |
jaroslav@874 | 14 |
* You should have received a copy of the GNU General Public License |
jaroslav@874 | 15 |
* along with this program. Look for COPYING file in the top folder. |
jaroslav@874 | 16 |
* If not, see http://opensource.org/licenses/GPL-2.0. |
jaroslav@874 | 17 |
*/ |
jaroslav@874 | 18 |
package org.apidesign.vm4brwsr; |
jaroslav@874 | 19 |
|
jaroslav@874 | 20 |
import java.io.IOException; |
jaroslav@874 | 21 |
import java.io.InputStream; |
jaroslav@874 | 22 |
import java.net.URL; |
jaroslav@874 | 23 |
import java.util.Enumeration; |
jaroslav@874 | 24 |
|
jaroslav@874 | 25 |
/** Implementation of Resources that delegates to some class loader. |
jaroslav@874 | 26 |
* |
jaroslav@874 | 27 |
* @author Jaroslav Tulach <jtulach@netbeans.org> |
jaroslav@874 | 28 |
*/ |
jaroslav@874 | 29 |
final class LdrRsrcs implements Bck2Brwsr.Resources { |
jaroslav@874 | 30 |
private final ClassLoader loader; |
jaroslav@1359 | 31 |
private final boolean skipRtJar; |
jaroslav@874 | 32 |
|
jaroslav@1359 | 33 |
LdrRsrcs(ClassLoader loader, boolean skipRtJar) { |
jaroslav@874 | 34 |
this.loader = loader; |
jaroslav@1359 | 35 |
this.skipRtJar = skipRtJar; |
jaroslav@874 | 36 |
} |
jaroslav@874 | 37 |
|
jaroslav@874 | 38 |
@Override |
jaroslav@874 | 39 |
public InputStream get(String name) throws IOException { |
jaroslav@874 | 40 |
Enumeration<URL> en = loader.getResources(name); |
jaroslav@874 | 41 |
URL u = null; |
jaroslav@874 | 42 |
while (en.hasMoreElements()) { |
jaroslav@874 | 43 |
u = en.nextElement(); |
jaroslav@874 | 44 |
} |
jaroslav@874 | 45 |
if (u == null) { |
jaroslav@874 | 46 |
throw new IOException("Can't find " + name); |
jaroslav@874 | 47 |
} |
jaroslav@1411 | 48 |
if (skipRtJar && u.toExternalForm().contains("lib/rt.jar!")) { |
jaroslav@1359 | 49 |
return null; |
jaroslav@1359 | 50 |
} |
jaroslav@874 | 51 |
return u.openStream(); |
jaroslav@874 | 52 |
} |
jaroslav@874 | 53 |
} |