• Post Reply Bookmark Topic Watch Topic
  • New Topic

Base 64 encoding  RSS feed

 
Vilas Kulkarni
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried an example code for Base64 encoding & decoding an object data.
I get an InvalidClassException with a Serialization error while trying to read the object from the decoded data (using ObjectInputStream).

I could verify that the string data (of the original object) and the one after encoding and decoding, are identical, by writing the content to files and comparing them. So there's no problem with the Base64 encoder.
I tried changing the serial version uid but it was of no use.

Exception message & stack trace:

Exception in thread "main" java.io.InvalidClassException: java.util.ArrayList; l
ocal class incompatible: stream classdesc serialVersionUID = 8664875232659988799
, local class serialVersionUID = 8683452581122892189
at java.io.ObjectStreamClass.initNonProxy(ObjectStreamClass.java:546)
at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:155
2)
at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1466)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1
699)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1305)
at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:19
08)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1832)

at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1
719)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1305)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:348)
at Base64EncodingExample.testEncodingAndDecoding(Base64EncodingExample.j
ava:64)
at Base64EncodingExample.main(Base64EncodingExample.java:12)


Here's the method which throws the above exception at the call to readObject().

public void testEncodingAndDecoding(TestObject testObj) throws IOException,ClassNotFoundException {

ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);

oos.writeObject(testObj);
byte[] testObjData = baos.toByteArray();
oos.flush();
oos.close();
baos.close();
String testObjDataStr = new String(testObjData);

String base64TestObjDataStr = Base64Coder.encodeString(testObjDataStr);
String origTestObjDataStr = Base64Coder.decodeString(base64TestObjDataStr);


/*
PrintStream p1 = new PrintStream(new FileOutputStream("TEST_OBJ_1.txt"),true);
printStream p2 = new PrintStream(new FileOutputStream("TEST_OBJ_.txt"),true);

p1.println(testObjDataStr);
p2.println(origTestObjDataStr);


p1.close();
p2.close();*/



byte[] origTestObjData = origTestObjDataStr.getBytes();
ByteArrayInputStream bis = new ByteArrayInputStream(origTestObjData);
ObjectInputStream ois = new ObjectInputStream(bis);
TestObject origTestObj = (TestObject) ois.readObject();

bis.close();
ois.close();

System.out.println("\n\nTEST OBJECT DATA\n"+testObj.toString()+
"\n\nEncoded and Decoded TEST OBJECT DATA\n"+origTestObj.toString());


return;
}


Can anybody point out any mistake in this or provide the solution?

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