Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

java.io.StreamCorruptedException

807591Jun 16 2008 — edited Jun 16 2008
Hello

I am using jasper reports and one of its following method gives me exception:

METHOD

public static Object loadObject(File file) throws JRException
{
if (!file.exists() || !file.isFile())
{
throw new JRException( new FileNotFoundException(String.valueOf(file)) );
}

Object obj = null;

FileInputStream fis = null;
ObjectInputStream ois = null;

try
{
byte[] b=null;

fis = new FileInputStream(file);

BufferedInputStream bufferedIn = new BufferedInputStream(fis);

int i=bufferedIn.read(b);

ois = new ObjectInputStream(bufferedIn);_
obj = ois.readObject();
}
catch (IOException e)
{
throw new JRException("Error loading object from file : " + file, e);
}
catch (ClassNotFoundException e)
{
throw new JRException("Class not found when loading object from file : " + file, e);
}
finally
{
if (ois != null)
{
try
{
ois.close();
}
catch(IOException e)
{
}EXCEPTION Thrown is
}

if (fis != null)
{
try
{
fis.close();
}
catch(IOException e)
{
}
}
}

return obj;
}

EXCEPTION Thrown is

Caused by: java.io.StreamCorruptedException: invalid stream header: D0CF11E0
at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:783)
at java.io.ObjectInputStream.<init>(ObjectInputStream.java:280)
at net.sf.jasperreports.engine.util.JRLoader.loadObject(JRLoader.java:90)





This is thrown on bold underlined line when I try to convert InputStream to ObjectInputStream.


I have tried different files but same exception is thrown.

Any help will be appriciated.





Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 14 2008
Added on Jun 16 2008
9 comments
3,109 views