Android Question java.io.EOFException: Unexpected end of ZLIB input stream

ThePlankton

Member
Licensed User
Longtime User
I use the following code to read and write a custom type to file. I keep seeing this random error when attempting to read the file.

java.io.EOFException: Unexpected end of ZLIB input stream

Am I missing something when writing?

Writing:
        Dim b As B4XSerializator
        Dim OutBytes() As Byte = b.ConvertObjectToBytes(objData)
       
        If OutBytes.Length = 0 Then Return 'INVALID
       
        File.WriteBytes(strDir, strFilename, OutBytes)

Reading:
        Dim b As B4XSerializator
        Dim objData As Object
       
        Dim bytes() As Byte = File.ReadBytes(strDir, strFilename)

        Dim objData As Object = b.ConvertBytesToObject(bytes)
 

zed

Well-Known Member
Licensed User
The java.io.EOFException: Unexpected end of ZLIB input stream error indicates that the ZLIB decompressor is expecting more data than is available—in other words, the file is incomplete or corrupted at the time of reading. And as you mentioned, this happens randomly, which suggests a problem during writing.

If you read the file immediately after writing it, the system may not have finished flushing it to disk yet.

Checks that the write operation is complete.
Adds a Sleep(100) or confirmation after File.WriteBytes.
Use File.Exists and check the size
 
Upvote 0

ThePlankton

Member
Licensed User
Longtime User
The java.io.EOFException: Unexpected end of ZLIB input stream error indicates that the ZLIB decompressor is expecting more data than is available—in other words, the file is incomplete or corrupted at the time of reading. And as you mentioned, this happens randomly, which suggests a problem during writing.

If you read the file immediately after writing it, the system may not have finished flushing it to disk yet.

Checks that the write operation is complete.
Adds a Sleep(100) or confirmation after File.WriteBytes.
Use File.Exists and check the size
Thanks for the reply. The read isnt immediately after the write so I don't believe its not fully flushed. Once this error happens the file is corrupt going forward.

I'll add some of the checks you mention though. Thanks
 
Upvote 0
Top