33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
+
|
self = [super init];
if (isa == [OFStream class])
@throw [OFNotImplementedException newWithClass: isa
selector: _cmd];
cache = NULL;
wcache = NULL;
return self;
}
- (BOOL)atEndOfStream
{
if (cache != NULL)
|
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
|
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
|
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
|
} @finally {
[self freeMemory: tmp];
}
/* Get rid of a warning, never reached anyway */
assert(0);
}
- cacheWrites
{
use_wcache = YES;
return self;
}
- flushWriteCache
{
[self writeNBytesWithoutCache: wcache_len
fromBuffer: wcache];
[self freeMemory: wcache];
wcache = NULL;
wcache_len = 0;
use_wcache = NO;
return self;
}
- (size_t)writeNBytes: (size_t)size
fromBuffer: (const char*)buf
{
if (!use_wcache)
return [self writeNBytesWithoutCache: size
fromBuffer: buf];
else {
wcache = [self resizeMemory: wcache
toSize: wcache_len + size];
memcpy(wcache + wcache_len, buf, size);
wcache_len += size;
return size;
}
}
- (size_t)writeNBytesWithoutCache: (size_t)size
fromBuffer: (const char*)buf
{
@throw [OFNotImplementedException newWithClass: isa
selector: _cmd];
}
- (void)writeInt8: (uint8_t)int8
{
[self writeNBytes: 1
|
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
|
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
|
-
-
-
+
-
-
-
-
-
-
-
+
-
-
-
-
-
+
+
-
-
|
{
return [self writeNBytes: [str cStringLength]
fromBuffer: [str cString]];
}
- (size_t)writeLine: (OFString*)str
{
size_t len = [str cStringLength];
char *tmp;
size_t ret = [self writeString: str];
tmp = [self allocMemoryWithSize: len + 2];
memcpy(tmp, [str cString], len);
tmp[len] = '\n';
tmp[len + 1] = '\0';
@try {
return [self writeNBytes: len + 1
[self writeInt8: '\n'];
fromBuffer: tmp];
} @finally {
[self freeMemory: tmp];
}
return ret + 1;
/* Get rid of a warning, never reached anyway */
assert(0);
}
- (size_t)writeFormat: (OFString*)fmt, ...
{
va_list args;
char *t;
size_t len;
|