本文整理汇总了C++中QTemporaryFile::read方法的典型用法代码示例。如果您正苦于以下问题:C++ QTemporaryFile::read方法的具体用法?C++ QTemporaryFile::read怎么用?C++ QTemporaryFile::read使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTemporaryFile
的用法示例。
在下文中一共展示了QTemporaryFile::read方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: readwrite
void tst_qtemporaryfile::readwrite()
{
QFETCH(qint64, amount);
const int dataSize = 4096;
QByteArray data;
data.fill('a', dataSize);
QBENCHMARK {
for (qint64 i = 0; i < amount; ++i) {
QTemporaryFile file;
file.open();
file.write(data);
file.seek(0);
file.read(dataSize);
file.close();
}
}
}
示例2: musicFile
bool KNMusicTagApev2::writeTag(const KNMusicAnalysisItem &analysisItem)
{
//Write the data according to the detail info.
const KNMusicDetailInfo &detailInfo=analysisItem.detailInfo;
//Check the file is still exist or not.
QFile musicFile(detailInfo.filePath);
//If the file is not exist then return false.
if(!musicFile.exists())
{
return false;
}
//Find the original tag data.
//ID3v1 header flag.
bool hasId3v1=false;
//Generate a header structure.
APEHeader header;
//Generate the raw tag data list.
QList<APETagItem> itemList;
//Initial the tag start position.
qint64 tagDataStart=-1, tagDataLength=-1;
//Open the file first.
if(musicFile.open(QIODevice::ReadOnly))
{
//Generate a data stream.
QDataStream musicDataStream(&musicFile);
if(musicFile.size() > 128)
{
//ID3v1 header cache.
char id3v1Header[3];
//Check whether there's ID3v1 tag in the music file.
musicDataStream.skipRawData(musicFile.size()-128);
//Read ID3v1 header.
musicDataStream.readRawData(id3v1Header, 3);
//Check the header, and we can know that whether there's ID3v1
//header.
hasId3v1=(id3v1Header[0]=='T' &&
id3v1Header[1]=='A' &&
id3v1Header[2]=='G');
}
//Check the beginning of the file.
if(checkHeader(0,
musicDataStream,
header))
{
//Set the tag data start.
tagDataStart=0;
//Set the tag length to header length.
tagDataLength=header.size;
//Check whether is a footer in the tag.
if(header.size > APEv2HeaderSize)
{
//Check the footer.
APEHeader footer;
//Tried to parse the footer.
if(checkHeader(header.size,
musicDataStream,
footer))
{
//Update the tag length.
tagDataLength+=APEv2HeaderSize;
}
}
//Reset the device to start.
musicDataStream.device()->reset();
//Skip the file data.
musicDataStream.skipRawData(APEv2HeaderSize);
}
//Check the end of the file.
else if(checkHeader(musicFile.size()-APEv2HeaderSize,
musicDataStream,
header))
{
//Save the tag start data.
int tagContentStart=musicFile.size()-header.size;
//Check the footer.
APEHeader footer;
//Check whether there's a header in the tag.
if(checkHeader(tagContentStart-APEv2HeaderSize,
musicDataStream,
footer))
{
//Save the tag data start position as the header start position.
//This is APEv2 tag.
tagDataStart=tagContentStart-APEv2HeaderSize;
//The tag length will be a header size + tag size.
tagDataLength=APEv2HeaderSize + header.size;
}
else
{
//This is APEv1 tag.
tagDataStart=tagContentStart;
//The tag length will be tag size.
tagDataLength=header.size;
}
//Reset the device to start.
musicDataStream.device()->reset();
//Skip the file data.
musicDataStream.skipRawData(tagContentStart);
}
//.........这里部分代码省略.........
示例3: writeDetail
bool KNMusicCueListParser::writeDetail(const KNMusicAnalysisItem &analysisItem)
{
//Get the track index.
const KNMusicDetailInfo &detailInfo=analysisItem.detailInfo;
//Prepare the orignial file data and the temporary file data.
QTemporaryFile updatedListFile;
QFile listFile(detailInfo.trackFilePath);
//Open the list file.
if(!listFile.open(QIODevice::ReadOnly))
{
return false;
}
//Open the list file.
if(!updatedListFile.open())
{
//Close the opened music file.
listFile.close();
return false;
}
//Read the list file.
//Initial the list file and temporary file stream as a text file.
QTextStream trackStream(&listFile), temporaryStream(&updatedListFile);
//Read until the track index comes to the track index.
QString rawLine=trackStream.readLine();
//Check the raw line.
while(!rawLine.isNull())
{
//Simplified the raw line.
QString commandRawLine=rawLine.simplified();
//Generate command part and data part cache.
QString rawCommand, rawData;
//Parse the command.
parseCommand(commandRawLine, rawCommand, rawData);
//Now we are only taken care about the TRACK.
if(rawCommand=="TRACK")
{
//Use the trackIndex variable find the space temporarily.
int trackIndex=rawData.indexOf(' ');
//Get the track index.
trackIndex=
(trackIndex==-1?rawData:rawData.left(trackIndex)).toInt();
//Check the track index.
if(trackIndex==detailInfo.trackIndex)
{
//Hit the track.
//First we have to output the raw line data.
temporaryStream << rawLine << '\n';
//Then check the detail info data.
//We have to write out these informations:
// PERFORMER Artist
// TITLE Name
QString trackData;
trackData.append(generateLine(
" TITLE ",
detailInfo.textLists[Name].toString()));
trackData.append(generateLine(
" PERFORMER ",
detailInfo.textLists[Artist].toString()));
//Write the track data to temporary file.
temporaryStream << trackData;
//Read the original file again until to INDEX, skip all the
//other data.
rawLine=trackStream.readLine();
//Simplified the raw line.
commandRawLine=rawLine.simplified();
//Parse the raw line.
parseCommand(commandRawLine, rawCommand, rawData);
//Read until we get the INDEX.
while(!rawLine.isNull() && rawCommand!="INDEX")
{
//Continue skip the file.
rawLine=trackStream.readLine();
//Simplified the raw line.
commandRawLine=rawLine.simplified();
//Parse the raw line.
parseCommand(commandRawLine, rawCommand, rawData);
}
//So now the data should be the first INDEX.
//Output the data and continue copy the data.
temporaryStream << rawLine << '\n';
}
else
{
//Simply output the data.
temporaryStream << rawLine << '\n';
}
}
else
{
//Simply output the data.
temporaryStream << rawLine << '\n';
}
//Read the next line.
rawLine=trackStream.readLine();
}
//Flush the data.
temporaryStream << flush;
//Now the data should be all done.
//Close the list file.
listFile.close();
//.........这里部分代码省略.........
示例4: musicFile
//.........这里部分代码省略.........
//Stop searching.
break;
}
}
//Combine the meta expand list data.
QByteArray metaRawData=combineBoxList(metaExpandList);
//Clear up the meta expand list.
metaExpandList.clear();
//Append the first four bytes raw data to the meta box raw data.
metaRawData.prepend(metaBox.data, 4);
//Clear up the no use meta box.
clearBox(metaBox);
clearBox(updatedIlstBox);
//Set the data to new meta box.
metaBox.name="meta";
metaBox.independence=true;
metaBox.size=metaRawData.size();
metaBox.data=new char[metaBox.size];
memcpy(metaBox.data, metaRawData.data(), metaBox.size);
//Replace the original meta box.
for(int i=udtaExpandList.size()-1; i>-1; --i)
{
//Check the name.
if(udtaExpandList.at(i).name=="meta")
{
//Replace the item.
udtaExpandList.replace(i, metaBox);
//Stop Searching.
break;
}
}
//Combine the udta data together.
M4ABox updatedUdtaBox=zipBox("udta", udtaExpandList);
//Clear the list and original udta box.
udtaExpandList.clear();
clearBox(udtaBox);
//Replace the original udta box.
for(int i=moovExpandList.size()-1; i>-1; --i)
{
//Check the name.
if(moovExpandList.at(i).name=="udta")
{
//Replace the item
moovExpandList.replace(i, updatedUdtaBox);
//Stop searching.
break;
}
}
//Combine the moov data together.
M4ABox updatedMoovBox=zipBox("moov", moovExpandList);
//Clear the list and original moov box.
moovExpandList.clear();
clearBox(moovBox);
//Write the new moov box to the updated tag file.
writeBox(updatedMoovBox, updatedTagFile);
//Clear up the updated moov box.
clearBox(updatedMoovBox);
//Copy the left data to the updated tag file.
//Generate the music data cache.
char *turboCache=new char[DataCacheSize];
//Copy the music data from the original music file, copy the
//MusicDataCacheSize bytes once, until there's no bytes to copy.
int bytesRead=musicFile.read(turboCache, DataCacheSize);
while(bytesRead>0)
{
//Write the cache to temporary file.
updatedTagFile.write(turboCache, bytesRead);
//Read new data from the original file to cache.
bytesRead=musicFile.read(turboCache, DataCacheSize);
}
//Close the music file.
musicFile.close();
//Reset the temporary file.
updatedTagFile.reset();
//Reopen the music file as write only mode, write all the udpated tag file
//data to the music file.
if(!musicFile.open(QIODevice::WriteOnly))
{
//Close the updated tag file.
updatedTagFile.close();
//Failed to write data.
return false;
}
//Copy data from temporary file to music file.
bytesRead=updatedTagFile.read(turboCache, DataCacheSize);
while(bytesRead>0)
{
//Write the cache to music file.
musicFile.write(turboCache, bytesRead);
//Read new data from cache to the original file.
bytesRead=updatedTagFile.read(turboCache, DataCacheSize);
}
//Close the music file and temporary file.
musicFile.close();
updatedTagFile.close();
//Clear up the turbo memory.
delete[] turboCache;
//The tag rewrite is finished.
return true;
}
示例5: ExtractTar
bool Packaging::ExtractTar(QTemporaryFile& tarFile, PackageData *packageData)
{
TarHeader tarHeader;
if (!tarFile.open())
{
Alerts::DisplayError(QString("Error opening temporary TAR archive:\n%1").arg(tarFile.fileName()));
return (false);
}
bool previousEmpty = false;
QProgressDialog progressDialog("Extracting files...", "Cancel", 0, tarFile.size());
progressDialog.setWindowModality(Qt::ApplicationModal);
progressDialog.setWindowTitle("Heimdall Frontend");
while (!tarFile.atEnd())
{
qint64 dataRead = tarFile.read(tarHeader.buffer, TarHeader::kBlockLength);
if (dataRead != TarHeader::kBlockLength)
{
progressDialog.close();
Alerts::DisplayError("Package's TAR archive is malformed.");
tarFile.close();
return (false);
}
progressDialog.setValue(tarFile.pos());
if (progressDialog.wasCanceled())
{
tarFile.close();
progressDialog.close();
return (false);
}
//bool ustarFormat = strcmp(tarHeader.fields.magic, ustarMagic) == 0;
bool empty = true;
for (int i = 0; i < TarHeader::kBlockLength; i++)
{
if (tarHeader.buffer[i] != 0)
{
empty = false;
break;
}
}
if (empty)
{
if (previousEmpty)
{
// Two empty blocks in a row means we've reached the end of the archive.
break;
}
}
else
{
int checksum = 0;
for (char *bufferIndex = tarHeader.buffer; bufferIndex < tarHeader.fields.checksum; bufferIndex++)
checksum += static_cast<unsigned char>(*bufferIndex);
checksum += 8 * ' ';
checksum += static_cast<unsigned char>(tarHeader.fields.typeFlag);
// Both the TAR and USTAR formats have terrible documentation, it's not clear if the following code is required.
/*if (ustarFormat)
{
for (char *bufferIndex = tarHeader.fields.linkName; bufferIndex < tarHeader.fields.prefix + 155; bufferIndex++)
checksum += static_cast<unsigned char>(*bufferIndex);
}*/
bool parsed = false;
// The size field is not always null terminated, so we must create a copy and null terminate it for parsing.
char fileSizeString[13];
memcpy(fileSizeString, tarHeader.fields.size, 12);
fileSizeString[12] = '\0';
qulonglong fileSize = QString(fileSizeString).toULongLong(&parsed, 8);
if (!parsed)
{
progressDialog.close();
Alerts::DisplayError("Tar header contained an invalid file size.");
tarFile.close();
return (false);
}
if (fileSize > 0 && tarHeader.fields.typeFlag == '0')
{
// We're working with a file.
QString filename = QString::fromUtf8(tarHeader.fields.name);
//.........这里部分代码省略.........