Questions tagged [eofexception]

An exception that occurs when reading from a stream or file, and indicates that the end of the stream has been reached. For example, you had expected to read 4 bytes from a stream with DataInputStream.readFully(), or an object with ObjectInputStream.readObject(), but end of stream was encountered instead.

An exception that occurs when reading from a stream or file, and indicates that the end of the stream has been reached. For example, you had expected to read 4 bytes from a stream with DataInputStream.readFully(), or an object with ObjectInputStream.readObject(), but end of stream was encountered instead.

Even though the exception is named EOF for 'end of file', it is possible to get this exception when processing any data stream. The exception can occur as a result of many different actions, such as:

  1. Reading data from a socket connection that has already been closed by the peer and all prior pending data has already been read.
  2. Reading data from an empty file.

When reading from a stream, you should usually detect and handle this exception, as well as other stream-related exceptions such as timeouts, by wrapping your reads in a try-catch block. This will allow you to catch exceptions such as this, and perform an alternate operation, such as alerting the user of the error, or ending the logical connection at this end.

214 questions
1
vote
3 answers

Get EOFException while reading serialized object in Java

I have two methods, one that serialize the Object, and it works ok: public void record()throws RecordingException { ObjectOutputStream outputStream = null; try { outputStream = new ObjectOutputStream(new…
Muhammad Hewedy
  • 29,102
  • 44
  • 127
  • 219
1
vote
1 answer

Client-Server using socket: Exception in thread "main" java.io.EOFException

I am writing simple client-server program where server is listening for all incoming connections and accepts them. Once accepted, client sends data (integer) to server and server echoes back the integer to client. This part works fine. Additionally…
Korba
  • 435
  • 1
  • 4
  • 18
1
vote
2 answers

Workaround java.io.EOFException cause by ObjectInputStream

For my application I want to use a Map to act as a database. To save and load a map, I am writing/reading it to/from database.ser using this 2 methods: private synchronized void saveDB() { try { fileOut = new FileOutputStream(db); …
GarRudo
  • 158
  • 1
  • 10
1
vote
1 answer

ObjectInputStream throws EOFexception when reading a file with an object in it

Im trying to read a Treemap from a file. I know that there is a TreeMap serialized in the file, my problem is that OIS throws an EOFexception on that file. public class FileDBMapApi { private FileOutputStream OutPutter; private…
1
vote
0 answers

How to deal with very large objects?

I am dealing with large Java object(single object may be as big as 1GB).When I try trasfering objects larger than 104004 KB it is throwing EOFException. Is it because my object is too large for the ObjectInputStream to hold or is there any other…
1
vote
2 answers

Android Volley EOFException

I have a simple app that uses volley like this: StringRequest stringRequest = new StringRequest(Request.Method.POST, url, new Response.Listener() { @Override public void onResponse(String…
Aurasphere
  • 3,841
  • 12
  • 44
  • 71
1
vote
0 answers

End of File Exception

Good day. I have a problem with my NodeJS server. I have an android app that gets information from MySQL database thru HttpUrlConnection every 30 seconds. The app and my server are working fine. But after about (not sure) 10 minutes or 20? my server…
something
  • 99
  • 12
1
vote
2 answers

How to test for instanceof in java correctly

I am testing an ObjectInputStream in Java. When I include the if statement, I get an EOF error. How do I properly test the object coming into the stream? The input stream object is of type byte[] array. if (ObjectInputStream.readObject()…
1
vote
1 answer

Java ObjectInputStream java.io.EOFException

I'm trying to pass data from MySQL to a client using a socket. For a List, I prefer using an array, but if I send an array using this: InputStream input = client.getInputStream(); OutputStream output = client.getOutputStream(); …
dav20011
  • 71
  • 3
  • 14
1
vote
1 answer

Spark Streaming Kafka Integration direct Approach EOFException

when i run spark streaming example org.apache.spark.examples.streaming.JavaDirectKafkaWordCount,i caught an EOFException follow,how can I resolve it Exception in thread "main" org.apache.spark.SparkException: java.io.EOFException: Received -1 when…
1
vote
0 answers

Retrofit POST java.io.EOFException

I'm trying to do a POST request to my server with a json body. If my POST request does not have body, it works. If I have any body content, I get this EOFException. Please let me know if I missed any detail. retrofit version 1.5.0 okhttp version…
heloisasim
  • 4,956
  • 2
  • 27
  • 36
1
vote
4 answers

Continuously read objects from an ObjectInputStream in Java

I have a problem using an ObjectInputStream and I have been struggling with it for 2 days now. I tried to search for a solution but unfortunately found no fitting answer. I am trying to write a client/server application in which the client sends…
1
vote
1 answer

Getting EOFException while trying to read from SSLSocket

I am developing a SSL client that will do a simple request to a SSL server and wait for the response. The SSL handshake and the writing goes OK but I can't READ data from the socket. I turned on the debug of java.net.ssl and got the following: [..]…
Isac
  • 2,058
  • 16
  • 23
1
vote
1 answer

android:get java.io.EOFException on press button

i have a button in my app that i want to when i press button app send a string to websrvice and get the result , this is my code : btn = (Button) findViewById(R.id.button_add_to_cart); btn.setTypeface(typeface); btn.setEnabled(false); …
mahdi
  • 16,257
  • 15
  • 52
  • 73
1
vote
2 answers

Why is this exception thrown and how to recover from it?

I am creating a remote-desktop screenshot application. I have two methods on the server 1) To read the Image from client 2) to read the list of task running on the client). But everytime I try to read the client's input stream an EOF excetion is…