0

Process-A writes bytes to a data-file using FileOutputStream. Process-B reads from the same data-file using DataInputStream.

The data-file resides on a NFS mount that doesn't support FileLocks so following approach is used:

Process-A creates a lock file to inform Process-B that it can start reading the data file. It creates the lock file after it flushes and closes the FileOutputStream. Process-B checks if the lock file exists and then starts reading the data-file. However, sometimes it encounters EOFException.

java.io.EOFException
        at java.io.DataInputStream.readFully(DataInputStream.java:180)
        at java.io.DataInputStream.readUTF(DataInputStream.java:592)
        at java.io.DataInputStream.readUTF(DataInputStream.java:547)


java.io.EOFException
        at java.io.DataInputStream.readInt(DataInputStream.java:375)
        at java.io.DataInputStream.readFloat(DataInputStream.java:429)

Can someone explain, what is going wrong? Also, is there any other alternative approach given that i can't use FileLock api?

Debajyoti Roy
  • 985
  • 2
  • 12
  • 34
  • maybe you can show the code that you use to write to and read from those streams? – Pavel Veller May 15 '12 at 18:42
  • I didnt paste any code because its the standard file i/o code using fileoutputstream and datainputstream, nothing out of hte ordinary. Only done in 2 different processes. – Debajyoti Roy May 15 '12 at 18:47
  • Possible duplicate of [EOFException - how to handle?](http://stackoverflow.com/questions/18451232/eofexception-how-to-handle) – Raedwald Mar 25 '16 at 17:32

1 Answers1

0

Nothing is going wrong. You have reached the end of the stream. The peer has closed his end of the connection. Close your end and forget about it.

user207421
  • 305,947
  • 44
  • 307
  • 483