Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Help! Getting java.io.StreamCorruptedException  RSS feed

 
Matt Senecal
Ranch Hand
Posts: 255
  • Mark post as helpful
  • send pies
  • 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?
 
Peter Tran
Bartender
Posts: 783
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • 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
  • 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

 
prasad bhn
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • 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

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!