1 22 package org.jboss.test.util; 23 24 import java.net.URL ; 25 import java.io.File ; 26 27 34 public class ClassMover 35 { 36 public static File move(String className) 37 throws ClassNotFoundException 38 { 39 File classFileBak = null; 40 String resName = className.replace('.', '/'); 41 URL classRes = ClassMover.class.getResource("/" + resName + ".class"); 42 if (classRes != null) 43 { 44 System.out.println("Found "+className+" impl at: " + classRes); 45 File classFile = new File (classRes.getFile()); 46 classFileBak = new File (classFile.getAbsolutePath() + ".bak"); 47 classFileBak.delete(); 48 boolean moved = classFile.renameTo(classFileBak); 49 System.out.println("Moved to .bak: " + moved); 50 } 51 else 52 { 53 throw new ClassNotFoundException ("No class file found: "+className); 54 } 55 return classFileBak; 56 } 57 58 public static void restore(File classFileBak) 59 { 60 if( classFileBak.exists() ) 61 { 62 String name = classFileBak.getAbsolutePath(); 63 String origName = name.substring(0, name.length() - 4); 64 File classFile = new File (origName); 65 boolean restored = classFileBak.renameTo(classFile); 66 System.out.println("Restored from .bak: " + restored); 67 } 68 } 69 } 70 | Popular Tags |