I have a code like this to make a serialize xml file:
private byte[] bytes;
...
OutputStream byteArrayOutputStream = new ByteArrayOutputStream();
XmlSerializer newSerializer = Xml.newSerializer();
newSerializer.setOutput(byteArrayOutputStream, "utf-8");
newSerializer.startDocument("utf-8", null);
newSerializer.startTag(null, "playlist");
newSerializer.attribute(null, "version", "1.0");
...
put all my XML tags
...
newSerializer.endTag(null, "playlist");
newSerializer.endDocument();
this.bytes= byteArrayOutputStream.toByteArray();
What i need to do: convert this byte Array into a XML file again and i don´t know how to do it!
You can change your existing serialisation and deserialisation as follows:
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream os = new ObjectOutputStream(baos);
os.writeObject(newSerializer);
ObjectInputStream oin = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()));
return (XmlSerializer) oin.readObject();
} catch (Exception e) {
throw new Exception("Exception occurred:" + e.getMessage(), e);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With