How small disk space can cause java. And about. EOFException

Today I came across strange behavior in Java serialization and deserialization ("weird" because I don't understand)

I serialized and deserialized the object from the linux shared directory. When serializing, everything worked without any problems, but when I tried to deserialize the same file, it throws java. io. EOFException java. io. EOFException java. io. EOFException . In addition, deserialization was unsuccessful only for this newly created file and worked for all other old files in this directory.

So, I searched the Internet and found one thread that said that this was also due to lack of disk space.

So, I cleared some temporary files and voila. I don’t understand how small disk space can only affect deserialization, not serialization?

I am using the apache commons SerializationUtils class. Below is the code for serializing and deserializing

 SerializationUtils. serialize(myObject, new FileOutputStream(new File(sharePath+FILEName) ; MyObject object=SerializationUtils. deserialize( new FileInputStream(new File(sharePath+FILEName); 

It would be very helpful if someone could explain this behavior. I suspect that his error in SerializationUtils may be throwing an IOException.

thanks

+5
source share
1 answer

My suspicion is that io is taken out when the file is written, because the time on the disk has run out, but the beginning of the serialized data was still being written to the disk. This would mean that the serialized data stored on disk is incomplete, so reading it will lead to invalid results, which in your case cause an EOF exception

To solve this problem, you need to see when an IO exception is generated due to lack of disk space with exception.getMessage() and remember to write incomplete data.

+7
source

Source: https://habr.com/ru/post/1260860/


All Articles