Consider the following code snippet.
DynamicMessage message; // somehow I created the message
// Writing directly to file
message.writeTo(new FileOutputStream("out.ser"));
// Wrinting through other stream
ByteArrayOutputStream baos = new ByteArrayOutputStream();
message.writeTo(baos);
BufferedWriter writer = new BufferedWriter(new FileWriter("out2.ser"));
writer.write(baos.toString());
writer.flush();
writer.close();
Now if I try to parse the same files using
DynamicMessage message2 = DynamicMessage.parsefrom(descriptor, "out.ser"); // Works
DynamicMessage message3 = DynamicMessage.parsefrom(descriptor, "out2.ser"); // Doesn't Work
I think in the .toString()
method has changed the encoding (possibly). Can anyone please suggest a way to serialize the message.writeTo()
to a string(Should be able to parse again).