This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Murach's Python Programming and have Michael Urban and Joel Murach on-line!
See this thread for details.



Only 44 hours left in the trailboss' kickstarter!

New rewards and stretch goals. CLICK HERE!



Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Instantiating a Java .class file from its InputStream  RSS feed

 
Anirvan Majumdar
Ranch Hand
Posts: 261
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

In my web application, I am supposed to allow the user to specify a .class file present on his/her system, and then instantiate it through the web app. The files get uploaded as formFile's and I can get the InputStream from them. However, the problem I'm facing is to convert this InputStream into it's corresponding class object.
I tried to do so using ObjectInputStream, but I rightfully got a java.io.StreamCorruptedException on the line where I try this:


Has anyone gotten out of this situation before?
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ObjectInputStream is for serialized objects, not for classes. Something like



should do the trick, after you've stored all the incoming bytes into a byte array. The ByteArrayOutputStream can help convert the stream to a byte array.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!