bool SimpleAbstractStreamReader::readFile(const QString &fileName) { QFile file(fileName); if (file.open(QIODevice::ReadOnly)) { QByteArray source = file.readAll(); file.close(); return readFromSource(QString::fromLocal8Bit(source)); } addError(tr("Cannot find file %1.").arg(fileName)); return false; }
size_t SeekableFilter::readData(File::Byte* buffer,size_t bufferSize) { /* Check if the file position needs to be moved to the read position: */ if(filePos!=readPos) { if(readPos>filePos) { /* Skip forward in buffer chain from the current position: */ currentPos+=(readPos-filePos); /* Skip buffers until the current buffer offset is within the current buffer: */ while(currentPos>Offset(current->size)) { /* Check if there is a next buffer: */ if(current->succ!=0) { /* Go to the next buffer: */ currentPos-=current->size; current=current->succ; } else { /* Check for end-of-file: */ if(source->eof()) throw SeekError(readPos); /* Read more data: */ readFromSource(); } } } else { /* Skip from the beginning of the buffer chain: */ current=head; currentPos=readPos; /* Skip buffers until the current buffer offset is within the current buffer: */ while(currentPos>Offset(current->size)) { /* Go to the next buffer: */ currentPos-=current->size; current=current->succ; } } /* Update the file position: */ filePos=readPos; } /* Check if the file position is at the end of the read data: */ if(filePos==totalReadSize) { /* Check for end-of-file: */ if(source->eof()) return 0; /* Read more data: */ readFromSource(); } /* Read from the current file position: */ if(currentPos==Offset(current->size)) { /* Go to the next buffer: */ current=current->succ; currentPos=0; } size_t copySize=current->size-size_t(currentPos); setReadBuffer(copySize,reinterpret_cast<Byte*>(current+1)+currentPos,false); readPos+=copySize; filePos+=copySize; currentPos+=copySize; return copySize; }