All pastes #2074594 Raw Edit

Anonymous

public text v1 · immutable
#2074594 ·published 2011-06-04 13:52 UTC
rendered paste body
- (void)stream:(NSStream *)stream handleEvent:(NSStreamEvent)eventCode {
    switch(eventCode) {
        case NSStreamEventHasBytesAvailable:
        {
            uint8_t buf[100];
            unsigned int len = 0;
            while ((len = (uint8_t)[(NSInputStream *)stream read:buf maxLength:100])) {
                NSString *tmp = [[[NSString alloc] initWithBytes:buf length:len encoding:NSASCIIStringEncoding] autorelease];
                leftovers = [leftovers stringByAppendingString:[tmp stringByReplacingOccurrencesOfString:@"\0" withString:@""]];
                NSArray *lines = [leftovers componentsSeparatedByString:@"\r\n"];
                NSLog(@"Lines: %@", lines);
                
                if (![[lines lastObject] hasSuffix:@"}"]) leftovers = [lines lastObject];
                else leftovers = @"";
                NSLog(@"Leftovers: %@", leftovers);
            }
            break;
        }
    }
}