I am working with a DataInputStream and had a question about EOFExceptions.
According to java docs:
Signals that an end of file or end of
stream has been reached unexpectedly
... |
Is it possible to ObjectOutputStream/ObjectInputStream an internal class? I can write it OK, and examine the created file, but when I try to read it back in using ObjectInputStream, I ... |
I want to read multiple objects (my own class Term) that I have output to a .dat file, but I always get a nullPointException or EOFException.
ObjectInputStream inputStream = new ObjectInputStream(new FileInputStream(masterFile));
...
|
It seems dirty to use an exception to indicate the end of a file has been reached. Every file we read has an end, so it doesn't seem exceptional or unexpected. ... |
Strange behavior. When I run a piece of logic in a Android Activity it works fine. But when I try to run that off a ActivityInstrumentationTestCase2 project, using a thread to ... |
I am writing an app that makes use of Object Output and Input Streams. However I have a problem, because I am not able to send my object properly. I write ... |
Hi Guys, firstly, I'm getting the EOFException while making ObjectInputStream instance and not ObjectOutputStream instance as mentioned in the subject matter !! Following is the code through which I 'm trying to read object : try { URL AdminLoginServlet = new URL("http://something.com/servlet/AdminLogin"); URLConnection servletConnection = AdminLoginServlet.openConnection(); servletConnection.setUseCaches(false); servletConnection.setDefaultUseCaches(false); servletConnection.setDoInput(true); ObjectInputStream inputFromServlet = new ObjectInputStream((InputStream)servletConnection.getInputStream()); String listNames = (String) inputFromServlet.readObject(); inputFromServlet.close(); } ... |
|
Hi, I made Client/Server program. The structure of my code is like below... First, client sends request to the server... Second, server receives the request and check the server status for the request. Third, server sends reply to the client Fourth, client receives the reply from the client. so on.... The problem is in fourth step. In the third step, server ... |
Hi all Java wizards, So I've decided to write a simple Log program. It uses Object Input/Output Streams. I whipped this quickly, but I am getting this weird EOFException and I cannot figure it out. The compiler doesn't like the line in bold. :confused: The actual complains are: at java.io.ObjectInputStream$BlockDataInputStream.pee kByte(Unknown Source) <-- the bold line at java.io.ObjectInputStream.readObject0(Unknown Source) at java.io.ObjectInputStream.readObject(Unknown ... |
thanks a lot ejp that helped, i actually did not consider the fact that readChar() will throw a EOFException by default at the end and hence didnt catch it, my bad... your suggestion solved the problem... i actually knew EOF means end of file, just failed to contemplate it... thank you guys |
|
|
|
Thank you for your response, I know where it happens because I've tried several different things while debugging. I've found that I can call s.getInputStream() without any errors in the same place, but as soon as I try to wrap it in an ObjectInputStream it throws an EOFException. I also have the stacktrace: java.io.EOFException at java.io.ObjectInputStream$PeekInputStream.readFully(ObjectInputStream.java:2279) at java.io.ObjectInputStream$BlockDataInputStream.readShort(ObjectInputStream.java:2748) at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:780) at ... |
The exception was thrown because TCP/IP generates a FIN on behalf of the interrupted process, so the reading process 'sees' a TCP EOS condition. However in Java how the EOS condition is manifested to your Java code depends what you're calling. If you're calling one of the basic read() methods they return -1. If you're calling a readLine() method it returns ... |
|