This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes  invalid stream header: 426F6172 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark " invalid stream header: 426F6172" Watch " invalid stream header: 426F6172" New topic
Author

invalid stream header: 426F6172

Rob Brew
Ranch Hand

Joined: Jun 23, 2011
Posts: 99
Hi all.

I'm running a client server architecture to send an objectOutputStream to the client. I get :

java.io.StreamCorruptedException: invalid stream header: 426F6172

I've googled this but cannot see an answer, here is the networking code:


and the client:


Thank you all in advance.

Rob.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14195
    
  20

On the sending side, you're using a PrintWriter to write to the output stream.

On the receiving side, you're using an ObjectInputStream to read.

These two I/O classes don't go together. An ObjectInputStream expects data in a specific binary format. A PrintWriter writes text. Either use an ObjectOutputStream on the sending side, or use a Reader on the reading side and parse the data appropriately.

Java has two kinds of I/O classes. Streams are for reading and writing binary data (bytes). Readers and Writers are for reading and writing text (characters), which are converted from and to bytes using a character encoding.

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
 
GeeCON Prague 2014
 
subject: invalid stream header: 426F6172