serialization - Append binary data to serialized xml header -
i need append binary data file before data xml header. whole file wont proper xml file must proper xml header following:
<encryptedfileheader> <algorithm>name</algorithm> <keysize>256</keysize> <subblocklength>64</subblocklength> <ciphermode>ecb</ciphermode> <sessionkey>sessionkey</sessionkey> </encryptedfileheader> *binary data* the xml header jaxb marshalling easily, , easier add binary data in base64 , store in note inside xml. clue. have store binary save overhead 33% space used base64.
so question how add data , of course later read (serialize/deserialize) ?
another question how remove first line of document?
i tried use:
marshaller.setproperty("com.sun.xml.bind.xmldeclaration", boolean.false); but throws exception:
javax.xml.bind.propertyexception: name: com.sun.xml.bind.xmldeclaration value: false @ javax.xml.bind.helpers.abstractmarshallerimpl.setproperty(abstractmarshallerimpl.java:358) @ com.sun.xml.internal.bind.v2.runtime.marshallerimpl.setproperty(marshallerimpl.java:527)
thanks
actualy solved serializing xml header jaxb, appending binary data (bytearray) existing file. reading file buffered reader follows:
bufferedreader reader = new bufferedreader(new filereader("filepath")); string line, results = ""; while ((line = reader.readline()) != null) { results += line; } reader.close(); string[] splited = results.split("</encryptedfileheader>"); splited[0] += "</encryptedfileheader>"; string s0 = splited[0]; string s1 = new string(splited[1]); bytearrayinputstream bais = new bytearrayinputstream(s0.getbytes()); now got problem second splited string s1, consist data "bytearrayoutputstream.tobytearray();". have transfer data string byte array. from:
'��a����g�x���
to like:
[39, -63, -116, 65, -123, -114, 27, -115, -2, 103, -64, 88, -99, -96, -26, -12]
i tried (on same machine): byte[] bytes = s1.getbytes();
but bytes array different , returns 34 bytes instead 16. read lot encodings still have no idea.
edit:
the problem different number of bytes due different representation of new line character , byte streams.
Comments
Post a Comment