jaroslav@874: /** jaroslav@874: * Back 2 Browser Bytecode Translator jaroslav@874: * Copyright (C) 2012 Jaroslav Tulach jaroslav@874: * jaroslav@874: * This program is free software: you can redistribute it and/or modify jaroslav@874: * it under the terms of the GNU General Public License as published by jaroslav@874: * the Free Software Foundation, version 2 of the License. jaroslav@874: * jaroslav@874: * This program is distributed in the hope that it will be useful, jaroslav@874: * but WITHOUT ANY WARRANTY; without even the implied warranty of jaroslav@874: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the jaroslav@874: * GNU General Public License for more details. jaroslav@874: * jaroslav@874: * You should have received a copy of the GNU General Public License jaroslav@874: * along with this program. Look for COPYING file in the top folder. jaroslav@874: * If not, see http://opensource.org/licenses/GPL-2.0. jaroslav@874: */ jaroslav@874: package org.apidesign.vm4brwsr; jaroslav@874: jaroslav@874: import java.io.IOException; jaroslav@874: import java.io.InputStream; jaroslav@874: import java.net.URL; jaroslav@874: import java.util.Enumeration; jaroslav@874: jaroslav@874: /** Implementation of Resources that delegates to some class loader. jaroslav@874: * jaroslav@874: * @author Jaroslav Tulach jaroslav@874: */ jaroslav@874: final class LdrRsrcs implements Bck2Brwsr.Resources { jaroslav@874: private final ClassLoader loader; jaroslav@1359: private final boolean skipRtJar; jaroslav@874: jaroslav@1359: LdrRsrcs(ClassLoader loader, boolean skipRtJar) { jaroslav@874: this.loader = loader; jaroslav@1359: this.skipRtJar = skipRtJar; jaroslav@874: } jaroslav@874: jaroslav@874: @Override jaroslav@874: public InputStream get(String name) throws IOException { jaroslav@874: Enumeration en = loader.getResources(name); jaroslav@874: URL u = null; jaroslav@874: while (en.hasMoreElements()) { jaroslav@874: u = en.nextElement(); jaroslav@874: } jaroslav@874: if (u == null) { jaroslav@874: throw new IOException("Can't find " + name); jaroslav@874: } jaroslav@1411: if (skipRtJar && u.toExternalForm().contains("lib/rt.jar!")) { jaroslav@1359: return null; jaroslav@1359: } jaroslav@874: return u.openStream(); jaroslav@874: } jaroslav@874: }