• 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

Help! Getting java.io.StreamCorruptedException

 
Ranch Hand
Posts: 255
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a class that updates a registry (not *the* registry) with serialized data. After writing data to the registry I can't read it and get the following exception:
java.io.StreamCorruptedException: Type code out of range, is -84
This suggests to me that there is a problem with the way I'm writing the data to the registry, but I can't pin the problem down. The code that does the (apparently corrupted) addition is:

Does anyone have any ideas?
 
Bartender
Posts: 783
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you paste more of your code or send it to me at ptran@javaranch.com? I'm would like to see the code that is reading in the object and what the class for "qlbd".
-Peter
 
Matt Senecal
Ranch Hand
Posts: 255
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sure! The code that does the reading is:

The code for QLBD is:

Originally posted by Peter Tran:
Can you paste more of your code or send it to me at ptran@javaranch.com? I'm would like to see the code that is reading in the object and what the class for "qlbd".
-Peter


 
Peter Tran
Bartender
Posts: 783
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Matt,
I took your code, and made a test run and didn't have problem serializing and de-serializing the QLButtonData class.
Here's my test program.

BTW, I added a public String name instance variable to the QLButtonData class to put something meaningful, so I could make sure that I was getting the same object back.
-Peter
 
Peter Tran
Bartender
Posts: 783
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One to note about your program, you should close resources in the order your open them. So in your program, you should swap the order of your close statements. E.g.
FileInputStream fis = new FileInputStream("Foo.txt");
BufferedInputStream bis = new BufferedInputStream(fis);
ObjectInputStream ois = new ObjectInputStream(bis);
Should then be closed in the reverse order.
ois.close();
bis.close();
fis.close();
Regards,
-Peter
 
Matt Senecal
Ranch Hand
Posts: 255
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for all the great help!
---Matt

Originally posted by Peter Tran:
One to note about your program, you should close resources in the order your open them. So in your program, you should swap the order of your close statements. E.g.
FileInputStream fis = new FileInputStream("Foo.txt");
BufferedInputStream bis = new BufferedInputStream(fis);
ObjectInputStream ois = new ObjectInputStream(bis);
Should then be closed in the reverse order.
ois.close();
bis.close();
fis.close();
Regards,
-Peter


 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi tran
i think once we close the innermost stream, it would automatically closes ALL the underlying streams. here,
we need only
ois.close();
bis and fis will be automatically closed. what do you say?

Originally posted by Peter Tran:
One to note about your program, you should close resources in the order your open them. So in your program, you should swap the order of your close statements. E.g.
FileInputStream fis = new FileInputStream("Foo.txt");
BufferedInputStream bis = new BufferedInputStream(fis);
ObjectInputStream ois = new ObjectInputStream(bis);
Should then be closed in the reverse order.
ois.close();
bis.close();
fis.close();
Regards,
-Peter


 
reply
    Bookmark Topic Watch Topic
  • New Topic