Solved

StreamCorruptedException  ?!

Posted on 2006-11-09
12
245 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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
simple java question 3 59
runtime exception 2 41
sql import cannot be resolved jsp 3 44
restrict decimal places for double datatype 10 19
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…

791 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