Re: How can I read an mbox file (or any simple data) in Cocoa?
Re: How can I read an mbox file (or any simple data) in Cocoa?
- Subject: Re: How can I read an mbox file (or any simple data) in Cocoa?
- From: Malte Tancred <email@hidden>
- Date: Sat, 15 Mar 2003 11:54:11 +0100
Denis Stanton wrote:
I'm trying to read the text from a Mail mbox file, but I cannot
determine the proper class to use to get that data. I know this is
pretty basic, but I have been through many documentation sources and I
haven't found the answer yet.
I think there has to be a lot of APIs for reading mbox files
out there. Perhaps pantomime will suit your needs?
http://www.collaboration-world.com/
I already have a WebObjects/Java program that does what I want. Now I
need to do the same thing in Cocoa. In my Java app I defined a
FileInputStream and a BufferedReader and then called .readLine on it.
I would dearly like to find something similar in the Cocoa API.
So would I.
can anybody suggest what I should be looking at to do this in Cocoa?
Yes.
I have got as far as;
NSString *thePath =
@"/Users/myname/Library/Mail/POP-myaccount/INBOX.mbox/mbox";
NSData *myData = [NSData dataWithContentsOfFile:thePath];
but everything I do with myData, such as [myData getBytes:aBuffer];
gives a sigbus error.
If you use -getBytes: make sure you allocate a buffer big enough
for the contents of the NSData.
If you're going the "C" way, looping over each character in the NSData,
you might use NSData's -bytes instead. This will access NSData's bytes
directly, without the need of the duplicate. This could actually be a
winner if you have big mbox files as well, as you can use
+dataWithContentsOfMappedFile:.
You can also use NSFileHandle. This solution is closer to your Java
code than using NSData. You call -readDataOfLength: and work on each
individual NSData retrieved. You can even do it asynchronously, and
you could replace the file with a socket or a pipe. Greater flexibility.
In my opinion it would be nice though if Apple provided a set of
Objective-C classes resembling the java.io package sometime in the
future.
Hope this helps.
Regards,
Malte
--
Malte Tancred
Computer Programmer
Oops AB,
http://oops.se/
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.