1 7 8 package org.gjt.jclasslib.io; 9 10 import org.gjt.jclasslib.bytecode.AbstractInstruction; 11 12 import java.io.ByteArrayOutputStream ; 13 import java.io.IOException ; 14 import java.util.Iterator ; 15 import java.util.List ; 16 17 24 public class ByteCodeWriter { 25 26 private ByteCodeWriter() { 27 } 28 29 35 public static byte[] writeByteCode(List instructions) throws IOException { 36 37 ByteArrayOutputStream baos = new ByteArrayOutputStream (); 38 ByteCodeOutputStream bcos = new ByteCodeOutputStream(baos); 39 40 Iterator it = instructions.iterator(); 41 while (it.hasNext()) { 42 writeNextInstruction(bcos, (AbstractInstruction)it.next()); 43 } 44 bcos.close(); 45 return baos.toByteArray(); 46 } 47 48 private static void writeNextInstruction(ByteCodeOutputStream bcos, 49 AbstractInstruction instruction) 50 throws IOException 51 { 52 instruction.write(bcos); 53 54 } 55 56 } 57 | Popular Tags |