dcsimg
Turn class to byte array as if reading class file
3 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Kai_Ruhl
Posted On:   Monday, April 9, 2001 02:23 AM

hello, having an arbitrary object (and thus its class thru getClass()) i want to turn it into a byte array _that is exactly the same as if i read the class file from disk_. then i want to send it over the network, recreate the Class and make a new object from it using newInstance(). i do _not_ have the class file available on the computer where the byte array arrives, nor do i have any information about that class except that it is Runnable. the ObjectOutputStream(ByteOutputStream(getClass())) does not work as obviously the Class object is a product of the class file but not the class file itself. RMI uses stubs. i dont want to do this. i have searched all jGuru (more carfully the section   More>>

hello,

having an arbitrary object (and thus its class thru getClass()) i want to turn it into a byte array _that is exactly the same as if i read the class file from disk_.

then i want to send it over the network, recreate the Class and make a new object from it using newInstance().

i do _not_ have the class file available on the computer where the byte array arrives, nor do i have any information about that class except that it is Runnable.

the ObjectOutputStream(ByteOutputStream(getClass())) does not work as obviously the Class object is a product of the class file but not the class file itself.

RMI uses stubs. i dont want to do this.

i have searched all jGuru (more carfully the sections "serialization", "networking", and "tools") and the all JDC, but found nothing appropriate.

any solution ?

best regards,

kai ruhl

   <<Less

Re: Turn class to byte array as if reading class file

Posted By:   Tim_Rohaly  
Posted On:   Thursday, April 19, 2001 11:05 AM

You can't do this.

Re: Turn class to byte array as if reading class file

Posted By:   Kai_Ruhl  
Posted On:   Friday, April 13, 2001 08:22 AM

Answering my own question.


I think this one is impossible. I have to load the byte code at least for the first time. Then I can overload ObjectOutputStream.annotateClass() and ObjectInputStream.resolveClass(), using my own ClassLoader (outer access to defineClass() and overload findClass()), also overloading readObject() and writeObject() to make sure the byte[] is taken from the object or set into it (any object should carry its byte[] itself).


If anyone knows a better solution, though, I would be thankful for it.

Re: Turn class to byte array as if reading class file

Posted By:   milo_mindbender  
Posted On:   Monday, April 9, 2001 10:08 AM

This sounds similar to class loading on a thin client - check out
http://www.javaworld.com/javaworld/javatips/jw-javatip39.html

for tips on class loading over a network -theres soem 'code that implements a URL connetion -> returning a class object as an array of bytes

see: method byte[] loadClassBytes(String className) on class URLClassLoader extends MultiClassLoader
on that link.

hope that this helps
:)
About | Sitemap | Contact