Path: blob/master/test/hotspot/jtreg/runtime/InvocationTests/shared/ByteArrayClassLoader.java
40948 views
/*1* Copyright (c) 2009, 2019, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324package shared;2526import java.util.HashMap;27import java.util.Map;2829/*******************************************************************/30// Class loader which has local class file storage in memory31/*******************************************************************/3233public class ByteArrayClassLoader extends ClassLoader {34private Map<String, byte[]> classes;3536public ByteArrayClassLoader() {37classes = new HashMap<String, byte[]>();38}3940public ByteArrayClassLoader(Map<String, byte[]> classes) {41this.classes = classes;42}4344public void appendClass(String name, byte[] classFile) {45classes.put(name, classFile);46}4748public Class findClass (String name) throws ClassNotFoundException {49if (classes.containsKey(name)) {50byte[] classData = classes.get(name);51return defineClass(name, classData, 0, classData.length);52} else {53throw new ClassNotFoundException("Can't find requested class: " + name);54}55}56}575859