@@ -39,31 +39,45 @@ cache = NULL; wcache = NULL; return self; } + +- (BOOL)_atEndOfStream +{ + @throw [OFNotImplementedException newWithClass: isa + selector: _cmd]; +} + +- (size_t)_readNBytes: (size_t)size + intoBuffer: (char*)buf +{ + @throw [OFNotImplementedException newWithClass: isa + selector: _cmd]; +} + +- (size_t)_writeNBytes: (size_t)size + fromBuffer: (const char*)buf +{ + @throw [OFNotImplementedException newWithClass: isa + selector: _cmd]; +} - (BOOL)atEndOfStream { if (cache != NULL) return NO; - return [self atEndOfStreamWithoutCache]; -} - -- (BOOL)atEndOfStreamWithoutCache -{ - @throw [OFNotImplementedException newWithClass: isa - selector: _cmd]; + return [self _atEndOfStream]; } - (size_t)readNBytes: (size_t)size intoBuffer: (char*)buf { if (cache == NULL) - return [self readNBytesWithoutCache: size - intoBuffer: buf]; + return [self _readNBytes: size + intoBuffer: buf]; if (size >= cache_len) { size_t ret = cache_len; memcpy(buf, cache, cache_len); @@ -84,17 +98,10 @@ return size; } } -- (size_t)readNBytesWithoutCache: (size_t)size - intoBuffer: (char*)buf -{ - @throw [OFNotImplementedException newWithClass: isa - selector: _cmd]; -} - - (void)readExactlyNBytes: (size_t)size intoBuffer: (char*)buf { size_t len = 0; @@ -233,11 +240,11 @@ /* Read until we get a newline or \0 */ tmp = [self allocMemoryWithSize: of_pagesize]; @try { for (;;) { - if ([self atEndOfStreamWithoutCache]) { + if ([self _atEndOfStream]) { if (cache == NULL) return nil; ret_len = cache_len; @@ -253,12 +260,12 @@ cache_len = 0; return ret; } - len = [self readNBytesWithoutCache: of_pagesize - intoBuffer: tmp]; + len = [self _readNBytes: of_pagesize + intoBuffer: tmp]; /* Look if there's a newline or \0 */ for (i = 0; i < len; i++) { if (OF_UNLIKELY(tmp[i] == '\n' || tmp[i] == '\0')) { @@ -374,11 +381,11 @@ /* Read until we get the delimiter or \0 */ tmp = [self allocMemoryWithSize: of_pagesize]; @try { for (;;) { - if ([self atEndOfStreamWithoutCache]) { + if ([self _atEndOfStream]) { if (cache == NULL) return nil; ret = [OFString stringWithCString: cache encoding: encoding @@ -389,12 +396,12 @@ cache_len = 0; return ret; } - len = [self readNBytesWithoutCache: of_pagesize - intoBuffer: tmp]; + len = [self _readNBytes: of_pagesize + intoBuffer: tmp]; /* Look if there's the delimiter or \0 */ for (i = 0; i < len; i++) { if (tmp[i] != delim[j++]) j = 0; @@ -467,12 +474,12 @@ return self; } - flushWriteCache { - [self writeNBytesWithoutCache: wcache_len - fromBuffer: wcache]; + [self _writeNBytes: wcache_len + fromBuffer: wcache]; [self freeMemory: wcache]; wcache = NULL; wcache_len = 0; use_wcache = NO; @@ -482,12 +489,12 @@ - (size_t)writeNBytes: (size_t)size fromBuffer: (const char*)buf { if (!use_wcache) - return [self writeNBytesWithoutCache: size - fromBuffer: buf]; + return [self _writeNBytes: size + fromBuffer: buf]; else { wcache = [self resizeMemory: wcache toSize: wcache_len + size]; memcpy(wcache + wcache_len, buf, size); wcache_len += size; @@ -494,17 +501,10 @@ 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 fromBuffer: (char*)&int8]; }