wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes problem in serialization Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "problem in serialization" Watch "problem in serialization" New topic
Author

problem in serialization

sadish kumar
Greenhorn

Joined: Jul 21, 2008
Posts: 7
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 ]
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19538
    
  16

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?


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
sadish kumar
Greenhorn

Joined: Jul 21, 2008
Posts: 7
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

Joined: Oct 27, 2005
Posts: 19538
    
  16

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: problem in serialization
 
Similar Threads
Help on Serializable
Writing/Reading multiple objects of same class using Serialization?
Problem with Objectuinputstream
java.io.EOFException using readObject
Serialization Query