Solved

StreamCorruptedException  ?!

Posted on 2006-11-09
12
239 Views
Last Modified: 2008-03-17
I'm able to do the following with no problems at all:


Socket server=..;
..

out=new DataOutputStream(server.getOutputStream());
in =new DataInputStream(server.getInputStream());
oos=new ObjectOutputStream(server.getOutputStream());


But when I try the following:


ois=new ObjectInputStream(server.getInputStream());


I get the following exception:

java.io.StreamCorruptedException: invalid stream header: 00095253
      at java.io.ObjectInputStream.readStreamHeader(Unknown Source)
           .
           .

(on the ObjectInputStream line..)


Help? :(

Thanks
0
Comment
Question by:InteractiveMind
  • 6
  • 4
  • 2
12 Comments
 
LVL 25

Author Comment

by:InteractiveMind
ID: 17910421
(The server-side is able to open all four streams no problem..)
0
 
LVL 92

Accepted Solution

by:
objects earned 400 total points
ID: 17910465
you cannot open a ObjectInputStream and DataInputStream on the same stream like that, ?(and it doesn't make a lot of sense to do it).
You can try opening the OIS first, but I'd suggest not opening a DataInputStream.
0
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 100 total points
ID: 17912482
Was the stream *written* with ObjectOutputStream?
0
ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

 
LVL 25

Author Comment

by:InteractiveMind
ID: 17920985
Sorry for the delay guys;

I now see that using a DataInputStream and an OutputInputStream is rather illogical; so I've cut it down to just an ObjectInputStream. This has stopped the exception.

However, now, although I'm able to open an ObjectOutputStream with no problem
oos=new ObjectOutputStream(server.getOutputStream());
my code just hangs when I attempt to open an ObjectInputStream
ois=new ObjectInputStream(server.getInputStream());

(I open the ois straight after the oos)

I'm stumped.
0
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 100 total points
ID: 17921063
Is that happening *before* you try to read from that input stream?
0
 
LVL 25

Author Comment

by:InteractiveMind
ID: 17921071
yes
0
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 100 total points
ID: 17921077
Is it definitely this line that causes it to hang?

>>ois=new ObjectInputStream(server.getInputStream());
0
 
LVL 25

Author Comment

by:InteractiveMind
ID: 17921083
I'm pretty sure it is, yea.

I'm doing the following to make sure:

oos=new ObjectOutputStream(server.getOutputStream());
System.out.println("o");
ois=new ObjectInputStream(server.getInputStream());
System.out.println("i");

It outputs o, but no i (and there's no exception or anything..)  :-\
0
 
LVL 25

Author Comment

by:InteractiveMind
ID: 17922954
well, i'm in the process of recoding my program.
hopefully that will solve the problem (as i'll be more cautious..); i'll get back to ya'll soon.
0
 
LVL 92

Expert Comment

by:objects
ID: 17923409
> my code just hangs when I attempt to open an ObjectInputStream

change the order you open things at the other end
0
 
LVL 25

Author Comment

by:InteractiveMind
ID: 17923541
I tried that as well :(


As it goes though, I finished recoding the program just a few mins ago--and am not getting any problems with it :-)
So I'll just put this hanging problem down to bad coding :-P  (it's a large code-and-fix app)

So, I will split the points (although most will be to objects for his solution to my initial issue).


Thanks very much both
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 17924383
:-)
0

Featured Post

ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
map related example 6 49
reverse digits of a number using for loop 5 42
even odd program using while loop 3 41
check java version using powershell 13 93
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question