/* */ #include "SingleFileAllocationIterator.h" #include "AbstractSingleDiskAdaptor.h" #define BUFSIZE 16*1024 SingleFileAllocationIterator::SingleFileAllocationIterator(AbstractSingleDiskAdaptor* diskAdaptor):_diskAdaptor(diskAdaptor), _offset(diskAdaptor->size()) {} SingleFileAllocationIterator::~SingleFileAllocationIterator() {} void SingleFileAllocationIterator::allocateChunk() { int32_t bufSize = BUFSIZE; unsigned char buf[BUFSIZE]; memset(buf, 0, bufSize); _diskAdaptor->writeData(buf, bufSize, _offset); _offset += bufSize; if(_diskAdaptor->getTotalLength() < _offset) { _diskAdaptor->truncate(getTotalLength()); _offset = getTotalLength(); } } bool SingleFileAllocationIterator::finished() { return getCurrentLength() >= getTotalLength(); } int64_t SingleFileAllocationIterator::getTotalLength() { return _diskAdaptor->getTotalLength(); }