UTFDataFormatException on Serialized Objects
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

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

I originally posted this in Servlets because what I'm working on is a servlet... then I realized this question didn't really have anything to do with servlets in particular. :) 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 ); objectOutputSt   More>>

I originally posted this in Servlets because what I'm working on is a servlet... then I realized this question didn't really have anything to do with servlets in particular. :)



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
About | Sitemap | Contact