forked from google/j2objc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNSDataOutputStream.m
61 lines (47 loc) · 1.07 KB
/
NSDataOutputStream.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
//
// NSDataOutputStream.m
// JreEmulation
//
// Created by Pankaj Kakkar on 5/20/13.
//
//
#import "NSDataOutputStream.h"
#import "IOSPrimitiveArray.h"
@interface NSDataOutputStream() {
@private
NSMutableData *data_;
}
@end
@implementation NSDataOutputStream
- (instancetype)init {
if ((self = [super init])) {
data_ = [[NSMutableData alloc] init];
}
return self;
}
+ (NSDataOutputStream *)stream {
return AUTORELEASE([[NSDataOutputStream alloc] init]);
}
#if ! __has_feature(objc_arc)
- (void)dealloc {
[data_ autorelease];
[super dealloc];
}
#endif
- (void)writeWithInt:(int)oneByte {
char byte = oneByte & 0xff;
[data_ appendBytes:&byte length:1];
}
- (void)writeWithByteArray:(IOSByteArray *)buffer
withInt:(int)offset
withInt:(int)count {
nil_chk(buffer);
NSUInteger originalLength = [data_ length];
[data_ increaseLengthBy:count];
jbyte *firstNewByte = ((jbyte *)[data_ mutableBytes]) + originalLength;
[buffer getBytes:firstNewByte offset:offset length:count];
}
- (NSData *)data {
return data_;
}
@end