• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

StreamCorruptedException

 
Ranch Hand
Posts: 485
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

Any idea??


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 ]
 
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you tested Class.getName() to make sure that it is a byte[] being returned? Some databases crypt the data when being stored and need to be decrypted. example: Base64

Also is there a reason why you are manually doing this yourself and not using a wrapper with java.io.Serializable?
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Parameswaran Thangavel
Ranch Hand
Posts: 485
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All
Thanks for your reply.

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.


still it throws the same error.....
 
Parameswaran Thangavel
Ranch Hand
Posts: 485
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ernest Friedman-Hill
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Parameswaran Thangavel
Ranch Hand
Posts: 485
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ernest,
you r right.

The problem is with the way we are writing the data into the DB.

When converting the object to byte array, the best way to do is use both
ByteArrayInputStream and ObjectInputStream....

Thanks to all...
 
Nick Meverden
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ernest Friedman-Hill
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I apologize; I definitely should have been nicer.
 
Nick Meverden
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
no worries
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic