package v2ch10.compiler;

import java.io.ByteArrayOutputStream;
import java.io.OutputStream;
import java.net.URI;
import javax.tools.SimpleJavaFileObject;

/**
 * A Java class that holds the byte codes in a byte array. Created by ZHEN on 16/9/18.
 */
public class ByteArrayJavaClass extends SimpleJavaFileObject {

   private ByteArrayOutputStream stream;

   public ByteArrayJavaClass(String name) {
      super(URI.create("bytes:///" + name), Kind.CLASS);
      this.stream = new ByteArrayOutputStream();
   }

   public OutputStream openOutputStream() {
      return stream;
   }

   public byte[] getBytes() {
      return stream.toByteArray();
   }
}
