I'm lazy so I would usually do something like this:
--------
NSData yourNSData = whateverYourDataIs();
String encoding = whatEverYourEncodingIs();
try {
String text = new String( yourNSData.bytes(), encoding );
NSArray<String> lines = NSArray.componentsSeparatedByString( text,
"\n" );
for( String line : lines ) {
doStuffToYour( line );
}
}
catch( UnsupportedEncodingException e ) {
logger.error( "Don't you know your encodings?", e );
}
--------
You could also use readLine() from an InputStreamReader wrapped in a
BufferedReader to read the ByteArrayInputStream returned
NSData.stream(), but I wouldn't go that way unless you need to
optimize memory use and performance. It's more complex, and I've had
horrifying problems with encodings when using the java.io.Reader-stuff
(apparenty the java-designers live an breathe ASCII).
But there's an example here if you want to go that way:
http://www.cafeaulait.org/slides/sd2000west/javaio/54.html
Cheers,
- Hugi
// Hugi Thordarson
// http://hugi.karlmenn.is/
On 5.1.2009, at 19:56, James Cicenia wrote:
I have an NSData object. I am using the sample AJAXFileUpload
which gives me an NSData object. I am reading in a tab delimited
text file and was wondering how do I read line per line.
Thanks
James Cicenia
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list ([email protected])
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/hugi%40karlmenn.is
This email sent to [email protected]
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list ([email protected])
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com
This email sent to [email protected]