All pastes #2074615 Raw Edit

Something

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