Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Why such Exception occour StreamCorruptedException  RSS feed

 
Parshuram Walunjkar
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
i am trying to send a Object from socket by using ObjectOutputStream but while reading i am using ObjectInputStream. I give such type of exception and then the Object come to client side.
problem while reading1 java.io.StreamCorruptedException: Type code out of range, is -84
problem while reading1 java.io.StreamCorruptedException: Unknown code in readObject -84
problem while reading1 java.io.StreamCorruptedException: Type code out of range, is -19
problem while reading1 java.io.StreamCorruptedException: Unknown code in readObject -19
problem while reading1 java.io.StreamCorruptedException: Type code out of range, is 0
problem while reading1 java.io.StreamCorruptedException: Type code out of range, is 5
problem while reading1 java.io.StreamCorruptedException: Unknown code in readObject 5
Why such exception occour. Please uell me solution .I hope that any one please help me.
Regard's and thanks
From Parshuram Walunjkar
 
Laudney Ren
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
public class StreamCorruptedException
extends ObjectStreamException
Thrown when control information that was read from an object stream violates internal consistency checks.
So, make sure your serialization of objects are valid.
 
Parshuram Walunjkar
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am using Object which implements Serializable interface .
So what is exach problem .
 
Laudney Ren
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess, maybe you have been trying to serialize a vector or component. All the objects related with a vector should also be serialized.
 
Parshuram Walunjkar
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,
I am sending program which i am using,
in server i put Vector Object as it contain String . String Object which implement's Serilizable interface ......
on server side
.......
...
ObjectOutputStream oos=new ObjectOutputStreamdata.getOutputStream());
Vector Data = new Vector();
Data.addElement("Parshuram Walunjkar");
oos.writeObject(Data);
......
.....
And on client side i am using on such type of code
This is run method of thread class which continously read information on server side
public void run()
{
...
...
ObjectInputStream ois=new ObjectInputStream(s.getInputStream());
Object ob = ois.readObject();
...
..
}//ens of method run
And it gives such type of exception as i told allready why such problem occur
 
Gillian Bladen-Clark
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You will get a StreamCorrupted error if an extra header has been written. I have had this when writing serialized objects to a file that already exists. The constructor for ObjectOutputStream is the culprit. To get round it I used ==>
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.io.IOException;
public class ReuseStream extends ObjectOutputStream {
public ReuseObjectOutputStream(OutputStream out) throws IOException {
super(out);
}
protected void writeStreamHeader() throws IOException {
reset();
}
}
if the file existed.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!