So this is my issue. A programs writes log files to a specific folder. Once a log file is created it is written to about every 2 seconds until it reaches approx 5MB. A new file is created then. I am Parsi g the log files to gather data real time.
I am using directory monitor to listen for changes to a directory. When a change is detected I am able to compare the NSfilemodocation date to get the newest file name name to monitor.
I then use that file name to create an NSinput stream. I create my buffer and I then open the stream and check if it "hasBytesAvail" and begin Parsing.
My issue is this: I am reaching the end of the file and EventEndOfStream is being called which destroys my stream.
I have two options:
keep a bytes read variable current until a new file is created. Which means every 2 seconds I need to be recreating the stream over and over, which seems like a waste.
Prevent the stream from being closed as long as the current file is the newest file in the directory. Which sounded simple, but in order to do that I have to read to the end of the file which triggers the stream to be closed and deallocated as well.
In its simplest terms I want to monitor a folder to get the name of a file to monitor. Then monitor the file and only read the new bytes since the last time it was read. Without needless instances of NSInputstream.
Does anyone have any suggestions?