UTFDataFormatException with Serialized Objects
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   John_Gallagher
Posted On:   Sunday, November 11, 2001 08:02 PM

I'm trying to update a sequential-access file (created with ObjectOutputStream and the like). To update an object, I'm copying the whole file to a temporary file, then copying back 1 object at a time, replacing the one to be updated with the updated one. Here's my (edited) code: while ( fileInputStream.available() > 0 ) { tempObject = ( MyObject )objectInputStream.readObject(); if ( tempObject.getIDNumber() == updateObject.getIDNumber() ) { objectOutputStream.writeObject( updateObject ); objectOutputStream.flush(); } else { objectOutputStream.writeObject( tempObject ); objectOutputStream.flush(); } } fileIn   More>>

I'm trying to update a sequential-access file (created with ObjectOutputStream and the like). To update an object, I'm copying the whole file to a temporary file, then copying back 1 object at a time, replacing the one to be updated with the updated one. Here's my (edited) code:


			
while ( fileInputStream.available() > 0 )
{
tempObject = ( MyObject )objectInputStream.readObject();

if ( tempObject.getIDNumber() == updateObject.getIDNumber() )
{
objectOutputStream.writeObject( updateObject );
objectOutputStream.flush();
}
else
{
objectOutputStream.writeObject( tempObject );
objectOutputStream.flush();
}
}



fileInputStream is a FileInputStream associated with the temporary file.

MyObject is obviously the object I'm using; "getIDNumber()" is the method that lets me figure out which one I'm supposed to update.

objectOutputStream is an ObjectOutputStream associated with the "real" (non-temp) file.



In practice, I can run this update once, and it gives no errors. But, if I try to run it again, it throws a UTFDataFormatException on the

tempObject = ( MyObject )objectInputStream.readObject();
line, leading me to believe something with the output is wrong. Any ideas?    <<Less

Re: UTFDataFormatException with Serialized Objects

Posted By:   Alex_Chaffee  
Posted On:   Sunday, December 23, 2001 01:13 PM

No, but you should ask on the IO FAQ or forum instead of the Servlets Forum.
About | Sitemap | Contact