views:

202

answers:

2

Java provides classes DataInputStream and DataOutputStream to read/write binary data (as bytes) in a structured way like DataInputStream.readInt()/readLong()/read(byte[]) from a byte stream; likewise for the DataOutputStream.

Are there equivalent classes or functions to the same in iPhone?

+2  A: 

NSData will do what you looking for I think:Core Data Class Reference

James Raybould
+1  A: 

Ram,

I feel your pain. Coming from Java land lots of things will feel backward or missing. NSData is your starting point but it works more like ByteArray stream classes as it holds the materialized data. Also beware that there are no formatting functions for serializing/deserializing data written/read to/from the source. In other words you won't find readInt(), readShort() in here. Do this: Cmd+Shift+? from XCode to call up help, type NSData to bring up the docs for it then click the link for the binary programming guide. Having dealt with an issue that may be exactly what you're about to hit, I'll warn you about the endian-ness of reading data on the iPhone from a stream that was written by Java. You'll have to swap byte orders from low to high. In other words if you use a DataOutputStream.writeInt() on one end (in something like a servlet) then try to map an int over the data read into an NSData object then swap byte orders.

Cliff