Licensing ITFoundation under the GNU General Public License version 2.
[ITFoundation.git] / ITByteStream.h
1 /*
2  *      ITFoundation
3  *      ITByteStream.h
4  *
5  *      Copyright (c) 2005 iThink Software
6  *
7  */
8
9 #import <Foundation/Foundation.h>
10
11 @protocol ITDataReceiver;
12
13 @protocol ITDataProvider <NSObject>
14 - (id <ITDataReceiver>)setDelegate:(id <ITDataReceiver>)delegate;
15 - (id <ITDataReceiver>)delegate;
16 @end
17
18 @protocol ITDataReceiver <NSObject>
19 -(oneway void)newDataAdded:(id <ITDataProvider>)sender;
20 @end
21
22 @interface ITByteStream : NSObject <ITDataProvider> {
23         @public
24         NSMutableData *data;
25         @private
26         NSLock *lock;
27         id <ITDataReceiver> delegate;
28 }
29
30 - (id)initWithDelegate:(id <ITDataReceiver>)delegate;
31 - (id)initWithStream:(ITByteStream *)stream delegate:(id <ITDataReceiver>)d;
32 - (int)availableDataLength;
33 - (NSData*)readDataOfLength:(int)length;
34 - (NSData*)readAllData;
35 - (void)writeData:(in NSData *)data;
36 - (void)writeBytes:(in char *)b len:(long)length;
37 - (void)lockStream;
38 - (void)unlockStream;
39 - (void)shortenData:(long)length;
40 - (id <ITDataReceiver>)setDelegate:(id <ITDataReceiver>)delegate;
41 - (id <ITDataReceiver>)delegate;
42
43 @end