How do I check if ObjectInputStream has something to read?

78 views Asked by At

I want to check if the ObjectInputStream has something to read or not. I used following techniques but nothing worked for me.

if((Packet) objectInputStream.readObject() != null) 

{

          //do something here

}

Other one is

try{

         objectInputStream.readObject();

}catch (IOException e){

         //do something here.         
 }

But when I write the statement objectInputStream.readObject() it stuck on that waiting for something to read. But I want it to return back returning null if there is nothing or throw exception. But it is doing nothing.

Here is another one.

objectInputStream.available().

In every case whether there is something to read or not it gives me 0.

0

There are 0 answers