What Am I Missing? : iPhone Objective-C NSInputStream initWithData

Posted by gabe on Stack Overflow See other posts from Stack Overflow or by gabe
Published on 2009-12-19T07:46:48Z Indexed on 2010/05/03 19:48 UTC
Read the original article Hit count: 355

I'm creating an NSInputStream from an NSData object but once created the stream reports NO for hasBytesAvailable:

NSData* data = [outputStream propertyForKey: NSStreamDataWrittenToMemoryStreamKey]; 
NSLog(@"creating stream with data 0x%x length %d", [data bytes], [data length]);
NSInputStream *insrm = [[NSInputStream alloc] initWithData:data];
[insrm open];

uint8_t* buf = NULL;
NSUInteger len;
BOOL result = [insrm getBuffer:&buf length:&len];
BOOL hasbytes = [insrm hasBytesAvailable];
NSLog(@"getBuffer:%d hasBytes:%d", result, hasbytes);
NSLog(@"created inputstream data %d len %d", buf, len);

Log:

[26797:20b] creating stream with data 0x7050000 length 34672
[26797:20b] getBuffer:0 hasBytes:0
[26797:20b] created inputstream data 0 len 0

What am I missing here?

© Stack Overflow or respective owner

Related posts about objective-c

Related posts about iphone