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@874: jaroslav@874: LdrRsrcs(ClassLoader loader) { jaroslav@874: this.loader = loader; jaroslav@874: } jaroslav@874: jaroslav@874: @Override jaroslav@874: public InputStream get(String name) throws IOException { lubomir@1029: Enumeration en = loader.getResources(name); lubomir@1029: URL u = null; lubomir@1029: while (en.hasMoreElements()) { lubomir@1029: u = en.nextElement(); lubomir@1029: } lubomir@1094: return (u != null) ? u.openStream() : null; lubomir@1020: } jaroslav@874: }