1

Hey guys, I have a Cocoa application that sends an NSDictionary over the network to various devices. Previously, it only sent to other Macs, so using NSKeyedArchiver to write to an NSData object worked fine, on the other end I would use an NSKeyedUnarchiver.

I now am writing a Java implementation for Windows support, and I need to convert the plist data, which is coming over the network like:

< 3c3f786d 6c207665 7273696f ... >

to a simple Java String. (So that I can read it with an XML parser.) The opposite seems to be answered here: [https://stackoverflow.com/questions/3774872] but I still can't quite wrap my head around what order I should be performing the encoding/decoding. 1

Community
  • 1
  • 1
Craig Otis
  • 31,257
  • 32
  • 136
  • 234

1 Answers1

2

The "string" you're seeing coming over the network is in fact the XML file as it appears in the raw.

If you're seeing it as a byte[] array object, it can be passed to a java.lang.String constructor:

byte[] theBytes = ...;
String theString = new String(theBytes, "UTF-8");

And from there to the XML parser.

If the actual bytes being transmitted over the network are '<', ' ', '3', 'c', etc., then something's wonky on the side sending the data because it appears to be converting the data into an NSString via the data's -description method before sending it. NSKeyedUnarchiver isn't smart enough to deal with such a string, so I don't suspect this is the case, but if it is, it's pretty simple to transform that back into the raw byte stream and then use the above Java constructor to get your XML string back.

Jonathan Grynspan
  • 43,286
  • 8
  • 74
  • 104
  • I believe you're correct in that the data is actually coming across the wire as plain-text XML, and the -description method is spitting out the bytes. I'll flesh out the read portion of the Windows impl and get back to you. – Craig Otis Jan 02 '11 at 03:32