Solved

StreamCorruptedException  ?!

Posted on 2006-11-09
12
259 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

691 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