1/*
2 * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24import java.io.FileInputStream;
25import java.io.InputStream;
26import java.io.IOException;
27import java.io.File;
28
29class SimpleClassLoader extends ClassLoader {
30    public static int numFinalizers;
31
32    SimpleClassLoader() {
33        super(null);
34    }
35
36    protected Class findClass(String name) throws ClassNotFoundException {
37        File f = new File(System.getProperty("test.classes"), name + ".class");
38        InputStream fi = null;
39        try {
40            fi = new FileInputStream(f);
41            int length = fi.available();
42            byte[] bytes = new byte[length];
43            fi.read(bytes, 0, length);
44            return defineClass(name, bytes, 0, length);
45        }
46        catch (IOException exception) {
47            // we could not find the class, so indicate the problem
48            throw new ClassNotFoundException(name, exception);
49        }
50        finally {
51            if (null != fi) {
52                try {
53                    fi.close();
54                } catch (IOException exception) {
55                }
56            }
57        }
58    }
59
60    protected void finalize() throws Throwable {
61        super.finalize();
62        numFinalizers++;
63    }
64}
65