Win a copy of Head First Android this week in the Android forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

problem in serialization

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
While i am trying to serialize an object, i got the following error. I have attached the code. Thanks in Advance

java.io.EOFException
at java.io.ObjectInputStream$PeekInputStream.readFully(ObjectInputStream.java:2247)
at java.io.ObjectInputStream$BlockDataInputStream.readShort(ObjectInputStream.java:2713)
at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:765)
at java.io.ObjectInputStream.<init>(ObjectInputStream.java:283)
My code is:



[edit]Add code tags. CR[/edit]
[ August 19, 2008: Message edited by: Campbell Ritchie ]
 
Sheriff
Posts: 22509
122
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The exception tells me that it is thrown when creating the ObjectInputStream. Apparently, the file is not created using serializing, or at least not the way you think.

How was this file created?
 
sadish kumar
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually we are getting the password from the user. By using the password, we are creating a file. After that we are serializing the file object. While serializing, i am getting this error.
Note: We are not write anything into the file. We are trying to encrypt the password.
 
Rob Spoor
Sheriff
Posts: 22509
122
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The code you're showing is not serializing anything. It's deserializing.

If you're not writing anything to the file, then of course it doesn't have a proper header.


If you're using this code for encrypting (and decrypting), there are better options. Check out javax.crypto.Cipher.

An example of encrypting, using Blowfish and a known encryption key:

Now one thing you should understand: encryption works on byte arrays, not Strings. You can convert between them like I did (using getBytes() and creating a new String), but the encrypted value will produce some "nasty" strings, with a lot of strange characters. A better solution would be to turn the byte array in a string with its HEX values. For instance, {4, 65, -124, 45} would be 0441842D.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic