JavaFileObject, how to supply byteCode byte array?

I have searched for a long time how to do a JavaFileObject which stores class byteCode. It does seem many people have related posting and understand how it works.

see for example, this posting
http://stackoverflow.com/questions/1168931/how-to-create-an-object-from-a-string-in-java-how-to-eval-a-string

my question is the class MemoryJavaFileObject

the method
public OutputStream openOutputStream() {
      return out;
    }
simply returns an OutputStream, which was initialized as a blank ByteArrayOutputStream.

The question is where and how does "out" ever get a byte array to make an output stream from.

another examples has

final class JavaFileObjectImpl extends SimpleJavaFileObject {
   // If kind == CLASS, this stores byte code from openOutputStream
   private ByteArrayOutputStream byteCode;

   // if kind == SOURCE, this contains the source text
   private final CharSequence source;


   JavaFileObjectImpl(final String baseName, final CharSequence source) {
      super(CharSequenceCompiler.toURI(baseName + CharSequenceCompiler.JAVA_EXTENSION),
            Kind.SOURCE);
      this.source = source;
   }

   /**
    * Construct a new instance
    *
    * @param name
    *           the file name
    * @param kind
    *           the kind of file
    */
   JavaFileObjectImpl(final String name, final Kind kind) {
      super(CharSequenceCompiler.toURI(name), kind);
      source = null;
   }


   @Override
   public CharSequence getCharContent(final boolean ignoreEncodingErrors)
         throws UnsupportedOperationException {
      if (source == null)
         throw new UnsupportedOperationException("getCharContent()");
      return source;
   }


   @Override
   public InputStream openInputStream() {
      return new ByteArrayInputStream(getByteCode());
   }


   @Override
   public OutputStream openOutputStream() {
      byteCode = new ByteArrayOutputStream();
      return byteCode;
   }

It is easy to see how it gets source content when it is a source file object. but for class code object, I don't see any way to direct the byteCode OutputStream to any real byte array.

Any body make sense of this? please help.
bhomassAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CEHJCommented:
Can you read the class file into an array?
0
bhomassAuthor Commented:
the class file is already in a byte array format. the question is how to make a JavaFileObject out of it. After that I am good.
0
bhomassAuthor Commented:
never mind.

the way to write in the bytecode is to use the OutputStream provided by openOutputStream() method. just use the write method.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
bhomassAuthor Commented:
I figured out by experimenting with code.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.