︙ | | | ︙ | |
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
cache = NULL;
writeBuffer = NULL;
blocking = YES;
return self;
}
- (BOOL)_isAtEndOfStream
{
@throw [OFNotImplementedException exceptionWithClass: [self class]
selector: _cmd];
}
- (size_t)_readIntoBuffer: (void*)buffer
length: (size_t)length
{
@throw [OFNotImplementedException exceptionWithClass: [self class]
selector: _cmd];
}
- (void)_writeBuffer: (const void*)buffer
length: (size_t)length
{
@throw [OFNotImplementedException exceptionWithClass: [self class]
selector: _cmd];
}
- copy
{
return [self retain];
}
- (BOOL)isAtEndOfStream
{
if (cache != NULL)
return NO;
return [self _isAtEndOfStream];
}
- (size_t)readIntoBuffer: (void*)buffer
length: (size_t)length
{
if (cache == NULL)
return [self _readIntoBuffer: buffer
length: length];
if (length >= cacheLength) {
size_t ret = cacheLength;
memcpy(buffer, cache, cacheLength);
[self freeMemory: cache];
cache = NULL;
|
|
|
|
|
|
|
|
|
|
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
cache = NULL;
writeBuffer = NULL;
blocking = YES;
return self;
}
- (BOOL)lowlevelIsAtEndOfStream
{
@throw [OFNotImplementedException exceptionWithClass: [self class]
selector: _cmd];
}
- (size_t)lowlevelReadIntoBuffer: (void*)buffer
length: (size_t)length
{
@throw [OFNotImplementedException exceptionWithClass: [self class]
selector: _cmd];
}
- (void)lowlevelWriteBuffer: (const void*)buffer
length: (size_t)length
{
@throw [OFNotImplementedException exceptionWithClass: [self class]
selector: _cmd];
}
- copy
{
return [self retain];
}
- (BOOL)isAtEndOfStream
{
if (cache != NULL)
return NO;
return [self lowlevelIsAtEndOfStream];
}
- (size_t)readIntoBuffer: (void*)buffer
length: (size_t)length
{
if (cache == NULL)
return [self lowlevelReadIntoBuffer: buffer
length: length];
if (length >= cacheLength) {
size_t ret = cacheLength;
memcpy(buffer, cache, cacheLength);
[self freeMemory: cache];
cache = NULL;
|
︙ | | | ︙ | |
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
|
}
}
/* Read and see if we get a newline or \0 */
buffer = [self allocMemoryWithSize: of_pagesize];
@try {
if ([self _isAtEndOfStream]) {
if (cache == NULL) {
waitingForDelimiter = NO;
return nil;
}
retLength = cacheLength;
|
|
|
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
|
}
}
/* Read and see if we get a newline or \0 */
buffer = [self allocMemoryWithSize: of_pagesize];
@try {
if ([self lowlevelIsAtEndOfStream]) {
if (cache == NULL) {
waitingForDelimiter = NO;
return nil;
}
retLength = cacheLength;
|
︙ | | | ︙ | |
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
|
cache = NULL;
cacheLength = 0;
waitingForDelimiter = NO;
return ret;
}
bufferLength = [self _readIntoBuffer: buffer
length: of_pagesize];
/* Look if there's a newline or \0 */
for (i = 0; i < bufferLength; i++) {
if OF_UNLIKELY (buffer[i] == '\n' ||
buffer[i] == '\0') {
retLength = cacheLength + i;
retCString = [self
|
|
|
|
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
|
cache = NULL;
cacheLength = 0;
waitingForDelimiter = NO;
return ret;
}
bufferLength = [self lowlevelReadIntoBuffer: buffer
length: of_pagesize];
/* Look if there's a newline or \0 */
for (i = 0; i < bufferLength; i++) {
if OF_UNLIKELY (buffer[i] == '\n' ||
buffer[i] == '\0') {
retLength = cacheLength + i;
retCString = [self
|
︙ | | | ︙ | |
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
|
}
}
/* Read and see if we get a delimiter or \0 */
buffer = [self allocMemoryWithSize: of_pagesize];
@try {
if ([self _isAtEndOfStream]) {
if (cache == NULL) {
waitingForDelimiter = NO;
return nil;
}
ret = [OFString stringWithCString: cache
encoding: encoding
length: cacheLength];
[self freeMemory: cache];
cache = NULL;
cacheLength = 0;
waitingForDelimiter = NO;
return ret;
}
bufferLength = [self _readIntoBuffer: buffer
length: of_pagesize];
/* Look if there's a delimiter or \0 */
for (i = 0; i < bufferLength; i++) {
if (buffer[i] != delimiterUTF8String[j++])
j = 0;
if (j == delimiterLength || buffer[i] == '\0') {
|
|
|
|
|
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
|
}
}
/* Read and see if we get a delimiter or \0 */
buffer = [self allocMemoryWithSize: of_pagesize];
@try {
if ([self lowlevelIsAtEndOfStream]) {
if (cache == NULL) {
waitingForDelimiter = NO;
return nil;
}
ret = [OFString stringWithCString: cache
encoding: encoding
length: cacheLength];
[self freeMemory: cache];
cache = NULL;
cacheLength = 0;
waitingForDelimiter = NO;
return ret;
}
bufferLength = [self lowlevelReadIntoBuffer: buffer
length: of_pagesize];
/* Look if there's a delimiter or \0 */
for (i = 0; i < bufferLength; i++) {
if (buffer[i] != delimiterUTF8String[j++])
j = 0;
if (j == delimiterLength || buffer[i] == '\0') {
|
︙ | | | ︙ | |
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
|
}
- (void)flushWriteBuffer
{
if (writeBuffer == NULL)
return;
[self _writeBuffer: writeBuffer
length: writeBufferLength];
[self freeMemory: writeBuffer];
writeBuffer = NULL;
writeBufferLength = 0;
}
- (void)writeBuffer: (const void*)buffer
length: (size_t)length
{
if (!writeBufferEnabled)
[self _writeBuffer: buffer
length: length];
else {
writeBuffer = [self resizeMemory: writeBuffer
size: writeBufferLength + length];
memcpy(writeBuffer + writeBufferLength, buffer, length);
writeBufferLength += length;
}
}
|
|
|
|
|
|
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
|
}
- (void)flushWriteBuffer
{
if (writeBuffer == NULL)
return;
[self lowlevelWriteBuffer: writeBuffer
length: writeBufferLength];
[self freeMemory: writeBuffer];
writeBuffer = NULL;
writeBufferLength = 0;
}
- (void)writeBuffer: (const void*)buffer
length: (size_t)length
{
if (!writeBufferEnabled)
[self lowlevelWriteBuffer: buffer
length: length];
else {
writeBuffer = [self resizeMemory: writeBuffer
size: writeBufferLength + length];
memcpy(writeBuffer + writeBufferLength, buffer, length);
writeBufferLength += length;
}
}
|
︙ | | | ︙ | |