Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Web Services and the fly likes Can't read same object multiple times Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "Can Watch "Can New topic
Author

Can't read same object multiple times

Darryl Failla
Ranch Hand

Joined: Oct 16, 2001
Posts: 129
I'm working with web services, JDeveloper, and JRLoader from Jasper Reports. JRLoader uses ObjectInputStream.readObject() to read the report object. It will read in the same object once or twice, but subsequent reads will throw a ClassNotFound exception. Why could this happen?


Darryl Failla
Sun Certified Java 2 Programmer
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12809
    
    5
Exactly what are your trying to do here?

It is the nature of ObjectInputStream that objects are only read once. If you can "rewind" the underlying InputStream, you would still need to create a new ObjectInputStram to get another copy of the object.

Bill
Darryl Failla
Ranch Hand

Joined: Oct 16, 2001
Posts: 129
I have a compiled jasper report: dodimrcat1.jasper. I'm using the code below to load the object. The loadObject() method in JRLoader throws a ClassNotFoundException when I run through this code a second time to service a second request. It appears to be in the deserializing of one of the classes contained in the report such as JRBaseLine or JRBaseRectangle.

File reportFile = new File("C:\\WS_examples\\dodimrcat1.jasper");
JasperReport jasperReport = null;
try
{
jasperReport = (JasperReport) JRLoader.loadObject(reportFile.getPath());
System.out.println("Got compiled report");
}catch(JRException jrExp){
jrExp.printStackTrace();
}
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12809
    
    5
That is a tough one! Perhaps JRLoader is not handling the file correctly at some point - have you tried to contact the author?
Is there some reason you have to use JRLoader instead of creating a regular ObjectInputStream directly?
Where have you placed the Jasper specific library files?
Bill
Darryl Failla
Ranch Hand

Joined: Oct 16, 2001
Posts: 129
Found the problem when I updated my version of JDeveloper from 9.0.4 to 9.0.5.2. From that point on, everything worked as expected.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Can't read same object multiple times