HI all, i am facing the below mentioned error when i tried to pass the byte array.
I am creating a XML and converting it to byte array before inserting into the DB, while retreivng i getting it as byte array and tried to view the object.
java.io.StreamCorruptedException: invalid stream header at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:737) at java.io.ObjectInputStream.<init>(ObjectInputStream.java:253) at com.cccis.interfaces.iatpa.reprocess.journal.JournalClient.convertBytesToObjectMsg(JournalClient.java:38) at com.cccis.interfaces.iatpa.reprocess.journal.JournalClient.main(JournalClient.java:121)
i am posting the code snippet for your reference....
i am passing the byte array and i am getting the error listed above...
[ July 03, 2006: Message edited by: Parameswaran Thangavel ]
This code looks fine; the problem is either on the other end (i.e., the code that encodes and inserts the bytes into the database) or it's the code that extracts the byte from the database.
As far as "testing getClass().getName()" -- I'm afraid that's not a very useful suggestion, given that there are no casts to or from byte here; and even if there were, using "instanceof byte" would be a far superior approach.
The defenition for ObjectInputStream says, "Creates an ObjectInputStream that reads from the specified InputStream. A serialization stream header is read from the stream and verified. This constructor will block until the corresponding ObjectOutputStream has written and flushed the header." I didn't understand what it meant by.
I completely have no idea what is mentioned there. Can any one let me know...
Further, i created a simple string object and coverted it to byte array to check whether its working ... but it didn't help.
Hi Nick I am afraid to say that i didn't understand your point "Also is there a reason why you are manually doing this yourself and not using a wrapper with java.io.Serializable?"
What i am doing here is Converting an XMLObject to byte array and store it in database using the service provided by service team. so i am unaware of how the byte array is get stored and usind the same service i am retrieving it back as XMLObject. Now i want to display this XML to the user. so i tried to conver the byte to Object. that where i faced the issue.
Hope this will help you all to understand my problem
I wouldn't worry about Nick's point, whatever it was.
ObjectInputStreams can only read streams of bytes created by ObjectOutputStreams. String.getBytes() does not return a serialized form of the String object, and so if this is how you're encoding your data, there's the problem right there.
Ernest Friedman-Hill why all the targeted aggression? I was just relating to a JNDI issue when retrieving passwords from OpenLDAP database that we thought were byte but ended up needing to be decrypted from Base64.