public Object run() throws IOException { bc.write(f); return null; } };
/** * Write the class bytecode to the specified file. */ public void write(File classFile) throws IOException { OutputStream out = new FileOutputStream(classFile); try { write(out); } finally { out.close(); } }
/** * Write the class bytecode to the specified file. */ public void write(File classFile) throws IOException { OutputStream out = new FileOutputStream(classFile); try { write(out); } finally { out.close(); } }
/** * Return the bytecode of this class as a byte array, possibly for use * in a custom {@link ClassLoader}. */ public byte[] toByteArray() { ByteArrayOutputStream out = new ByteArrayOutputStream(); try { write(out); out.flush(); return out.toByteArray(); } catch (IOException ioe) { throw new RuntimeException(ioe.toString()); } finally { try { out.close(); } catch (IOException ioe) {} } }
/** * Return the bytecode of this class as a byte array, possibly for use * in a custom {@link ClassLoader}. */ public byte[] toByteArray() { ByteArrayOutputStream out = new ByteArrayOutputStream(); try { write(out); out.flush(); return out.toByteArray(); } catch (IOException ioe) { throw new RuntimeException(ioe.toString()); } finally { try { out.close(); } catch (IOException ioe) {} } }
public static void write(BCClass bc, File outFile) throws IOException { if (bc.getMajorVersion() < Java7_MajorVersion) { bc.write(outFile); } else { OutputStream out = new FileOutputStream(outFile); try { writeJava7(bc, out); } finally { out.flush(); out.close(); } } }
public static void write(BCClass bc, File outFile) throws IOException { if (bc.getMajorVersion() < Java7_MajorVersion) { bc.write(outFile); } else { OutputStream out = new FileOutputStream(outFile); try { writeJava7(bc, out); } finally { out.flush(); out.close(); } } }
public static void write(BCClass bc, File outFile) throws IOException { if (bc.getMajorVersion() < Java7_MajorVersion) { bc.write(outFile); } else { OutputStream out = new FileOutputStream(outFile); try { writeJava7(bc, out); } finally { out.flush(); out.close(); } } }
public static void write(BCClass bc, File outFile) throws IOException { if (bc.getMajorVersion() < Java7_MajorVersion) { bc.write(outFile); } else { OutputStream out = new FileOutputStream(outFile); try { writeJava7(bc, out); } finally { out.flush(); out.close(); } } }
public static void write(BCClass bc, File outFile) throws IOException { if (bc.getMajorVersion() < Java7_MajorVersion) { bc.write(outFile); } else { OutputStream out = new FileOutputStream(outFile); try { writeJava7(bc, out); } finally { out.flush(); out.close(); } } }
private static void debugBytecodes(BCClass bc) throws IOException { // Write the bytecodes to disk for debugging purposes. if ("true".equals(System.getProperty( ManagedClassSubclasser.class.getName() + ".dumpBytecodes"))) { File tmp = new File(System.getProperty("java.io.tmpdir")); File dir = new File(tmp, "openjpa"); dir = new File(dir, "pcsubclasses"); dir.mkdirs(); dir = Files.getPackageFile(dir, bc.getPackageName(), true); File f = new File(dir, bc.getClassName() + ".class"); System.err.println("Writing to " + f); bc.write(f); } }
/** * Write the class bytecode to the .class file in the proper directory of * the CLASSPATH. The file must exist already, so this method only works * on existing classes. */ public void write() throws IOException { String name = getName(); int dotIndex = name.lastIndexOf('.') + 1; name = name.substring(dotIndex); Class type = getType(); // attempt to get the class file for the class as a stream; // we need to use the url decoder in case the target directory // has spaces in it OutputStream out = new FileOutputStream(URLDecoder.decode (type.getResource(name + ".class").getFile())); try { write(out); } finally { out.close(); } }
/** * Write the class bytecode to the .class file in the proper directory of * the CLASSPATH. The file must exist already, so this method only works * on existing classes. */ public void write() throws IOException { String name = getName(); int dotIndex = name.lastIndexOf('.') + 1; name = name.substring(dotIndex); Class type = getType(); // attempt to get the class file for the class as a stream; // we need to use the url decoder in case the target directory // has spaces in it OutputStream out = new FileOutputStream(URLDecoder.decode (type.getResource(name + ".class").getFile())); try { write(out); } finally { out.close(); } }
@SuppressWarnings("deprecation") public static void write(BCClass bc) throws IOException { if (bc.getMajorVersion() < Java7_MajorVersion) { bc.write(); } else { String name = bc.getName(); int dotIndex = name.lastIndexOf('.') + 1; name = name.substring(dotIndex); Class<?> type = bc.getType(); OutputStream out = new FileOutputStream( URLDecoder.decode(type.getResource(name + ".class").getFile())); try { writeJava7(bc, out); } finally { out.flush(); out.close(); } } }
@SuppressWarnings("deprecation") public static void write(BCClass bc) throws IOException { if (bc.getMajorVersion() < Java7_MajorVersion) { bc.write(); } else { String name = bc.getName(); int dotIndex = name.lastIndexOf('.') + 1; name = name.substring(dotIndex); Class<?> type = bc.getType(); OutputStream out = new FileOutputStream( URLDecoder.decode(type.getResource(name + ".class").getFile())); try { writeJava7(bc, out); } finally { out.flush(); out.close(); } } }
@SuppressWarnings("deprecation") public static void write(BCClass bc) throws IOException { if (bc.getMajorVersion() < Java7_MajorVersion) { bc.write(); } else { String name = bc.getName(); int dotIndex = name.lastIndexOf('.') + 1; name = name.substring(dotIndex); Class<?> type = bc.getType(); OutputStream out = new FileOutputStream( URLDecoder.decode(type.getResource(name + ".class").getFile())); try { writeJava7(bc, out); } finally { out.flush(); out.close(); } } }
@SuppressWarnings("deprecation") public static void write(BCClass bc) throws IOException { if (bc.getMajorVersion() < Java7_MajorVersion) { bc.write(); } else { String name = bc.getName(); int dotIndex = name.lastIndexOf('.') + 1; name = name.substring(dotIndex); Class<?> type = bc.getType(); OutputStream out = new FileOutputStream( URLDecoder.decode(type.getResource(name + ".class").getFile())); try { writeJava7(bc, out); } finally { out.flush(); out.close(); } } }
@SuppressWarnings("deprecation") public static void write(BCClass bc) throws IOException { if (bc.getMajorVersion() < Java7_MajorVersion) { bc.write(); } else { String name = bc.getName(); int dotIndex = name.lastIndexOf('.') + 1; name = name.substring(dotIndex); Class<?> type = bc.getType(); OutputStream out = new FileOutputStream( URLDecoder.decode(type.getResource(name + ".class").getFile())); try { writeJava7(bc, out); } finally { out.flush(); out.close(); } } }
public static void main(String[] args) throws IOException { Project project = new Project(); InputStream in = WASManagedRuntime.class.getClassLoader() .getResourceAsStream(CLASS.replace('.', '/') + ".class"); BCClass bcClass = project.loadClass(in); String [] interfaces = bcClass.getInterfaceNames(); if(interfaces != null) { for(int i = 0; i < interfaces.length; i++) { if(interfaces[i].equals(INTERFACE)) { return; } } } bcClass.declareInterface(INTERFACE); bcClass.write(); }