mgerdin@4637: /* mgerdin@4637: * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. mgerdin@4637: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. mgerdin@4637: * mgerdin@4637: * This code is free software; you can redistribute it and/or modify it mgerdin@4637: * under the terms of the GNU General Public License version 2 only, as mgerdin@4637: * published by the Free Software Foundation. mgerdin@4637: * mgerdin@4637: * This code is distributed in the hope that it will be useful, but WITHOUT mgerdin@4637: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or mgerdin@4637: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License mgerdin@4637: * version 2 for more details (a copy is included in the LICENSE file that mgerdin@4637: * accompanied this code). mgerdin@4637: * mgerdin@4637: * You should have received a copy of the GNU General Public License version mgerdin@4637: * 2 along with this work; if not, write to the Free Software Foundation, mgerdin@4637: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. mgerdin@4637: * mgerdin@4637: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA mgerdin@4637: * or visit www.oracle.com if you need additional information or have any mgerdin@4637: * questions. mgerdin@4637: */ mgerdin@4637: mgerdin@4637: import java.io.InputStream; mgerdin@4637: import java.nio.file.Files; mgerdin@4637: import java.nio.file.Path; mgerdin@4637: import java.nio.file.Paths; mgerdin@4637: import java.nio.file.StandardCopyOption; mgerdin@4637: mgerdin@4637: /** mgerdin@4637: * Dump a class file for a class on the class path in the current directory mgerdin@4637: */ mgerdin@4637: public class ClassFileInstaller { mgerdin@4637: /** mgerdin@4637: * @param args The names of the classes to dump mgerdin@4637: * @throws Exception mgerdin@4637: */ mgerdin@4637: public static void main(String... args) throws Exception { mgerdin@4637: for (String arg : args) { mgerdin@4637: ClassLoader cl = ClassFileInstaller.class.getClassLoader(); mgerdin@4637: mgerdin@4637: // Convert dotted class name to a path to a class file mgerdin@4637: String pathName = arg.replace('.', '/').concat(".class"); mgerdin@4637: InputStream is = cl.getResourceAsStream(pathName); mgerdin@4637: mgerdin@4637: // Create the class file's package directory mgerdin@4637: Path p = Paths.get(pathName); coleenp@5100: if (pathName.contains("/")) { coleenp@5100: Files.createDirectories(p.getParent()); coleenp@5100: } mgerdin@4637: // Create the class file mgerdin@4637: Files.copy(is, p, StandardCopyOption.REPLACE_EXISTING); mgerdin@4637: } mgerdin@4637: } mgerdin@4637: }