5 // Created by Alexander Strange on Thu Feb 27 2003.
6 // Copyright (c) 2003 __MyCompanyName__. All rights reserved.
9 #import "ITByteStream.h"
11 // TODO: Add NSCopying/NSCoding support. Blocking reads (how would this work? NSConditionLock?)
13 @implementation ITByteStream
16 if (self == [super init])
18 data = [[NSMutableData alloc] init];
19 lock = [[NSLock alloc] init];
25 -(id) initWithDelegate:(id)d
27 if (self == [super init])
29 data = [[NSMutableData alloc] init];
30 lock = [[NSLock alloc] init];
31 delegate = [d retain];
36 -(id) initWithStream:(ITByteStream*)stream delegate:(id)d
38 if (self == [super init])
40 data = [stream->data copy];
41 lock = [[NSLock alloc] init];
42 delegate = [d retain];
47 -(oneway void) dealloc
56 -(void) setDelegate:(id <ITByteStreamDelegate>)d
59 delegate = [d retain];
62 -(int) availableDataLength
71 -(NSData*) readDataOfLength:(int)length
74 NSRange range = {0, length};
76 ret = [data subdataWithRange:range];
77 #if MAC_OS_X_VERSION_10_2 <= MAC_OS_X_VERSION_MAX_ALLOWED
78 [data replaceBytesInRange:range withBytes:nil length:0];
80 range = {length, [data length]};
81 tmp = [data subdataWithRange:range];
88 -(NSData*) readAllData
92 ret = [data autorelease];
93 data = [[NSMutableData alloc] init];
98 -(void) writeData:(in NSData*)_data
101 [data appendData:_data];
103 [delegate newDataAdded:self];
106 -(void) writeBytes:(char *)b len:(long)length
109 [data appendBytes:b length:length];
111 [delegate newDataAdded:self];