test/testlibrary/ClassFileInstaller.java

Print this page




  28 import java.nio.file.StandardCopyOption;
  29 
  30 /**
  31  * Dump a class file for a class on the class path in the current directory
  32  */
  33 public class ClassFileInstaller {
  34     /**
  35      * @param args The names of the classes to dump
  36      * @throws Exception
  37      */
  38     public static void main(String... args) throws Exception {
  39         for (String arg : args) {
  40             ClassLoader cl = ClassFileInstaller.class.getClassLoader();
  41 
  42             // Convert dotted class name to a path to a class file
  43             String pathName = arg.replace('.', '/').concat(".class");
  44             InputStream is = cl.getResourceAsStream(pathName);
  45 
  46             // Create the class file's package directory
  47             Path p = Paths.get(pathName);

  48             Files.createDirectories(p.getParent());

  49             // Create the class file
  50             Files.copy(is, p, StandardCopyOption.REPLACE_EXISTING);
  51         }
  52     }
  53 }


  28 import java.nio.file.StandardCopyOption;
  29 
  30 /**
  31  * Dump a class file for a class on the class path in the current directory
  32  */
  33 public class ClassFileInstaller {
  34     /**
  35      * @param args The names of the classes to dump
  36      * @throws Exception
  37      */
  38     public static void main(String... args) throws Exception {
  39         for (String arg : args) {
  40             ClassLoader cl = ClassFileInstaller.class.getClassLoader();
  41 
  42             // Convert dotted class name to a path to a class file
  43             String pathName = arg.replace('.', '/').concat(".class");
  44             InputStream is = cl.getResourceAsStream(pathName);
  45 
  46             // Create the class file's package directory
  47             Path p = Paths.get(pathName);
  48             if (pathName.contains("/")) {
  49                 Files.createDirectories(p.getParent());
  50             }
  51             // Create the class file
  52             Files.copy(is, p, StandardCopyOption.REPLACE_EXISTING);
  53         }
  54     }
  55 }