+
+- (id <ITDataReceiver>)setDelegate:(id <ITDataReceiver>)d {
+ id old = delegate;
+ [delegate release];
+ delegate = [d retain];
+ return old;
+}
+
+- (id <ITDataReceiver>)delegate {
+ return delegate;
+}
+
+- (int)availableDataLength {
+ int len;
+ [lock lock];
+ len = [data length];
+ [lock unlock];
+ return len;
+}
+
+- (NSData*)readDataOfLength:(int)length {
+ NSData *ret;
+ NSRange range = {0, length};
+ [lock lock];
+ ret = [data subdataWithRange:range];
+ [data replaceBytesInRange:range withBytes:nil length:0];
+ [lock unlock];
+ return ret;
+}
+
+- (NSData*)readAllData {
+ NSData *ret;
+ [lock lock];
+ ret = [data autorelease];
+ data = [[NSMutableData alloc] init];
+ [lock unlock];
+ return ret;
+}
+
+- (void)writeData:(in NSData*)_data {
+ [lock lock];
+ [data appendData:_data];
+ [lock unlock];
+ [delegate newDataAdded:self];
+}
+
+- (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];
+}
+