Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Instantiating a Java .class file from its InputStream

 
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.
 
bacon. tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!