X-Git-Url: http://git.ithinksw.org/ITFoundation.git/blobdiff_plain/14a301f7aa7b244c4831006cfc4cfa42185517a4..0471d3908d12b15bd1962ad57402da9f838ce66c:/ITByteStream.m diff --git a/ITByteStream.m b/ITByteStream.m index 67ecf31..664e1a0 100755 --- a/ITByteStream.m +++ b/ITByteStream.m @@ -53,10 +53,17 @@ [super dealloc]; } --(void) setDelegate:(id )d +-setDelegate:(id )d { + id old = delegate; [delegate release]; delegate = [d retain]; + return old; +} + +-delegate +{ + return delegate; } -(int) availableDataLength @@ -70,17 +77,11 @@ -(NSData*) readDataOfLength:(int)length { - NSData *ret, *tmp; + NSData *ret; NSRange range = {0, length}; [lock lock]; ret = [data subdataWithRange:range]; -#if MAC_OS_X_VERSION_10_2 <= MAC_OS_X_VERSION_MAX_ALLOWED [data replaceBytesInRange:range withBytes:nil length:0]; -#else - range = {length, [data length]}; - tmp = [data subdataWithRange:range]; - [data setData:tmp]; -#endif [lock unlock]; return ret; } @@ -103,11 +104,27 @@ [delegate newDataAdded:self]; } --(void) writeBytes:(char *)b len:(long)length +-(void) writeBytes:(in char *)b len:(long)length { [lock lock]; [data appendBytes:b length:length]; [lock unlock]; [delegate newDataAdded:self]; } + +-(void) lockStream +{ + [lock lock]; +} + +-(void) unlockStream +{ + [lock unlock]; +} + +-(void) shortenData:(long)length +{ + NSRange range = {0, length}; + [data replaceBytesInRange:range withBytes:nil length:0]; +} @end