void ParseFiles() { int offset = outfile.tellp(); for(int i = 0; i < files.size(); i++) { ifstream infile(files[i].c_str(), ifstream::binary); int size = 0; infile.seekg(0, ios::end); size = infile.tellg(); infile.seekg(0, ios::beg); if(size == 0) continue; cout << "[+] " << files[i] << " size[" << setw(8) << setfill('0') << size << "]" << endl; char *data = new char[size]; infile.read(data,size); outfile.write(data,size); delete data; int curOffset = outfile.tellp(); outfile.seekp(8*i); outfile.write((char*)&offset,4); outfile.write((char*)&size,4); outfile.seekp(curOffset); offset += size; infile.close(); } }
void CQualLL::CreateFile(ofstream &fp){ char *block; ifstream fileTemp; size_t IndexPos = 0, pos_input = 0, end_input = 0, aux = 0, inpos = 1; if(CQual.length() != 0){ CQual = GZcompressString(CQual); SaveValue(fileQual, CQual.length()); SaveValue(fileQual, (char *)CQual.c_str(), CQual.length()); CQual = ""; } fileQual.close(); SaveValue(fp, LOSSLESS); cds_word Variables[2]; Variables[0] = IndexRate; Variables[1] = numberOfLines; SaveValue(fp, Variables, 2); buffer = init_buffer(); buffer_use = 0; if(IndexRate > 0){//this will be overwrite at the end IndexPos = fp.tellp(); IndexLine = new cds_word[1 + (numberOfLines + IndexRate - 1)/IndexRate]; for(cds_word w = 0; w < (1 + (numberOfLines + IndexRate - 1)/IndexRate); w++) IndexLine[w] = 0; SaveValue(fp, IndexLine, 1 + ((numberOfLines + IndexRate - 1)/IndexRate)); } init_qual = fp.tellp(); init_qual += 2 * sizeof(size_t); SaveValue(fp, init_qual); SaveValue(fp, end_qual); fileTemp.open(tmp_name.c_str()); pos_input = fileTemp.tellg(); fileTemp.seekg(0, std::ifstream::end); end_input = fileTemp.tellg(); fileTemp.seekg(pos_input); if(IndexRate > 0) IndexLine[0] = fp.tellp(); while(pos_input < end_input){ aux = LoadValue<size_t>(fileTemp); block = LoadValue<char>(fileTemp, aux); pos_input += aux + sizeof(size_t); SaveValue(fp, block, aux); if(IndexRate > 0){ IndexLine[inpos] = fp.tellp(); inpos ++; } delete [] block; } fileTemp.close(); end_qual = fp.tellp(); fp.seekp(IndexPos); if(IndexRate > 0) SaveValue(fp, IndexLine, (1 + (numberOfLines + IndexRate - 1)/IndexRate)); delete [] buffer; fp.seekp(init_qual - sizeof(size_t)); SaveValue(fp, end_qual); fp.seekp(end_qual); remove(tmp_name.c_str()); }
size_t dami::getFileSize(ofstream& file) { size_t size = 0; if (file.is_open()) { streamoff curpos = file.tellp(); file.seekp(0, ios::end); size = file.tellp(); file.seekp(curpos); } return size; }
/* Open the output file, initialize the output stream, and return the file's length. If reload is true, first truncate any preexisting file */ unsigned long Download::openfile(char *url, bool reload, ofstream &fout, char *name) { char fname[MAX_FILENAME_SIZE]; if(!getfname(url, fname)) throw DLExc("File name error"); for(int i = 0; i < 5 && (!fout.is_open() || !fout); ++i) { if(!reload) fout.open(fname, ios::binary | ios::out | ios::app | ios::ate); else fout.open(fname, ios::binary | ios::out | ios::trunc); if(!fout.is_open() || !fout) { char buff[MAX_FILENAME_SIZE]; strcpy(buff, fname); sprintf(fname, "%s-%u", buff, time(0)-i); fout.clear(); } } if(!fout) throw DLExc("Could not open TEMP file!"); strcpy(name, fname); // get current file length return fout.tellp(); }
//============================================================================ // CTzCpString::ExternaliseL //============================================================================ void CTzCpString::ExternaliseL(ofstream& aFilestream) { iOffset = (int)aFilestream.tellp() - iDocument.DbHeader()->iOffsetToStringTable; TUint8 stringLength = iString.length(); aFilestream.write((char*)&stringLength,sizeof(stringLength)); aFilestream << iString.c_str(); }
//============================================================================ // CTzCpRuleUse::ExternaliseL //============================================================================ void CTzCpRuleUse::ExternaliseL(ofstream& aFilestream) { iOffset = (int)aFilestream.tellp() - iDocument.DbHeader()->iOffsetToRuleUsesTable; iPersistedEntity.iOffsetToRuleDefinition = iRuleDefinitionPtr->iOffset; iPersistedEntity.iOffsetToRuleLetterString = iRuleLetterPtr->iOffset; aFilestream.write((char*)&iPersistedEntity,sizeof(iPersistedEntity)); }
static bool switch_log(ofstream &flog) { GenerateTime("pacs_log\\%Y\\%m\\%d\\%H%M%S_service_n.txt", buff, sizeof(buff)); if(flog.tellp() > 10 * 1024 * 1024 || strncmp(buff, current_log_path.c_str(), 20)) // 20 == strlen("pacs_log\\YYYY\\MM\\DD\\") { if(PrepareFileDir(buff)) { if(flog.is_open()) { time_header_out(flog) << "to be continued" << endl; flog.close(); } flog.open(buff); if(flog.fail()) { cerr << "watch_notify() switch log " << buff << " failed" << endl; return false; } time_header_out(flog) << "continuation of " << current_log_path << endl; current_log_path = buff; } else { DWORD gle = GetLastError(); cerr << "watch_notify() switch log failed, PrepareFileDir(" << buff << ") failed" << endl; return false; } } return true; }
void MQTTLogger::OnMessage(const struct mosquitto_message *message) { string topic = message->topic; string payload = static_cast<const char*>(message->payload); std::time_t tt = std::time(NULL); char mbstr[100]; std::strftime(mbstr, sizeof(mbstr), "%Y-%m-%d %H:%M:%S:", std::localtime(&tt)); string time(mbstr); Output << time + "\t" << topic + "\t" + payload << endl; if (Output.tellp() > Max){ Output.close(); int i; for (i = Number-1; i > 0; i--){ if (access((Path_To_Log + "." + to_string(i)).c_str(), F_OK) != -1){// check if old log file exists if (rename((Path_To_Log + "." + to_string(i)).c_str(), (Path_To_Log + "." + to_string(i+1)).c_str()) != 0){ cerr << "can't create old log file \n"; exit(-1); } } } if (rename(Path_To_Log.c_str(), (Path_To_Log + ".1").c_str()) != 0){ cerr << "can't create old log file \n"; exit(-1); } Output.open(Path_To_Log); if (!Output.is_open()){ cerr << "Cannot open log file for writting " << Path_To_Log << endl; exit (-1); } mosquittopp::unsubscribe(NULL, Mask.c_str());// unsubscribe and subscribe to save all retained messages after rotate Subscribe(NULL, Mask); } }
//============================================================================ // CTzCpRuleSet::ExternaliseL //============================================================================ void CTzCpRuleSet::ExternaliseL(ofstream& aFilestream) { iOffset = (int)aFilestream.tellp() - iDocument.DbHeader()->iOffsetToRuleSetsTable; iPersistedEntity.iNumberOfRuleUses = iVector.size(); aFilestream.write((char*)&iPersistedEntity,sizeof(iPersistedEntity)-sizeof(iPersistedEntity.iOffsetsToRuleUses)); TUint16 ruleUseOffset; for (int x = 0; x < iPersistedEntity.iNumberOfRuleUses;x++) { ruleUseOffset = iVector[x]->iOffset; aFilestream.write((char*)&ruleUseOffset,sizeof(ruleUseOffset)); } }
void MakeImage::WriteSector(ofstream &stream, int sectorNum, char *data) { int writePos = sectorNum * SECTOR_SIZE; // get end of file pos stream.seekp(0, ios::end); int endPos = stream.tellp(); if(endPos <= writePos) { do { stream.put(0); endPos = stream.tellp(); } while(endPos <= writePos); } stream.seekp(writePos); stream.seekp(0, ios_base::cur); stream.write(data, SECTOR_SIZE); }
//============================================================================ // CTzCpRegionalZonesIndex::ExternaliseL //============================================================================ void CTzCpRegionalZonesIndex::ExternaliseL(ofstream& aFilestream) { iOffset = (int)aFilestream.tellp() - iDocument.DbHeader()->iOffsetToRegionalZonesTable; // sort zone index alphabetically before externalising it sort(iZoneIndex.begin(),iZoneIndex.end(),CTzCpZone::SZoneNameSort()); iPersistedEntity.iNumberOfZones = iZoneIndex.size(); aFilestream.write((char*)&iPersistedEntity,sizeof(iPersistedEntity) - sizeof(iPersistedEntity.iOffsetsToZones)); //Write out the zone offsets for (int x = 0; x < iPersistedEntity.iNumberOfZones;x++) { TUint16 zoneOffset = iZoneIndex[x]->iOffset; aFilestream.write((char*)&zoneOffset,sizeof(zoneOffset)); } }
//============================================================================ // CTzCpZone::ExternaliseL //============================================================================ void CTzCpZone::ExternaliseL(ofstream& aFilestream) { iOffset = (int)aFilestream.tellp() - iDocument.DbHeader()->iOffsetToZones; iPersistedEntity.iLocationId = iLocationId; iPersistedEntity.iOffsetToZoneName = iZoneNameRef->iOffset; iPersistedEntity.iOffsetToRegionName = iRegionNameRef->iOffset; iPersistedEntity.iNumberOfStdTimeAlignments = iTimeAlignments.size(); aFilestream.write((char*)&iPersistedEntity,sizeof(iPersistedEntity)-sizeof(iPersistedEntity.iOffsetsToTimeAlignments)); //Externalise the time alignment offsets for (int x = 0; x < iPersistedEntity.iNumberOfStdTimeAlignments; x++) { TUint16 stdoffset = iTimeAlignments[x]->iOffset; aFilestream.write((char*)&stdoffset,sizeof(stdoffset)); } }
//============================================================================ // CTzCpStdTimeAlignment::ExternaliseL //============================================================================ void CTzCpStdTimeAlignment::ExternaliseL(ofstream& aFilestream) { iOffset = (int)aFilestream.tellp() - iDocument.DbHeader()->iOffsetToStdTimeAlignmentsTable; //Retrieve the ruleset offset iPersistedEntity.iOffsetToRuleSet = iRuleSet->iOffset; //Retrieve the time zone format name offset iPersistedEntity.iOffsetToTimeZoneFormatName = iDocument.StringTable()->Strings()[iPersistedEntity.iOffsetToTimeZoneFormatName]->iOffset; //Set the number of time zones iPersistedEntity.iNumberOfTimeZones = iOffsetsToTimeZonesShortNames.size(); aFilestream.write((char*)&iPersistedEntity,sizeof(iPersistedEntity)-sizeof(iPersistedEntity.iOffsetsToTimeZones)); //Write the time zone offsets int size = iOffsetsToTimeZonesShortNames.size(); for (int x = 0; x < size; x++) { TUint16 offsetToTimeZone = iOffsetsToTimeZonesShortNames[x]->iOffset; aFilestream.write((char*)&offsetToTimeZone,sizeof(offsetToTimeZone)); } }
void __stdcall vcamOpenLog(int verbosity, char* message) { #ifdef _DEBUG { CAutoLock l(&debugLock); if (numUsers == 0) { BOOL ok = CreateDirectory(VCAM_DEBUG_DIRNAME, NULL); if (!ok && GetLastError() == ERROR_ALREADY_EXISTS) { ok = TRUE; } if (ok) { try { debugOut.exceptions(ios::failbit); debugOut.open(VCAM_DEBUG_FNAME, ios_base::app); // Truncate log if it's too big debugOut.seekp(0, ios_base::end); if (debugOut.tellp() > 1024 * 256) { debugOut.close(); debugOut.open(VCAM_DEBUG_FNAME, ios_base::trunc); } openedOK = TRUE; } catch (...) { openedOK = FALSE; } } else { openedOK = FALSE; } if (!openedOK && !showedLogWarning) { Msg("Couldn't open multicam log file,\r\nso no logging will be performed"); showedLogWarning = TRUE; } } numUsers++; } vcamLog(verbosity, "%s opened log, numUsers = %d", message, numUsers); #endif }
int StatRandomVibrationSimulation::sampletofile(int nstep, ofstream& record) { long streampos=record.tellp(); //nt sz=U->Size(); // record.write(reinterpret_cast<const char*>(&time), sizeof(time)); // double val; for( int i=0 ; i<nstep; i++) { val=(*samplExc)(i); record.write( reinterpret_cast<const char*>(&val), sizeof( val)); } for(int i=0 ; i<nstep; i++) { val=(*samplResp)(i); record.write( reinterpret_cast<const char*>(&val), sizeof( val)); } record.flush(); return streampos; }
//============================================================================ // CTzCpRuleDefinition::ExternaliseL //============================================================================ void CTzCpRuleDefinition::ExternaliseL(ofstream& aFilestream) { iOffset = (int)aFilestream.tellp() - iDocument.DbHeader()->iOffsetToRuleDefinitionsTable; aFilestream.write((char*)&iPersistedEntity,sizeof(iPersistedEntity)); }
streampos ftellp(ofstream &fout) { return fout.tellp(); }
void CRPSPreMF::CreateFile(ifstream &SamFile, ofstream &fp, int SamOrRps, vector<cds_word>* IndexClusterToLines){ cds_word *index; size_t index_pos = 0; getValuesPreSeq(posWin, WINSIZE); // get for last time the values from winSeq for(cds_word j = 0; j < WINSIZE; j++) //free winSeq delete [] WinSeq[j]; delete [] WinSeq; if(tmp_file_string.length() > 0){ fileSeq << tmp_file_string; //write to fileQual (it must exist) tmp_file_string = ""; } ClusterIndex[ClusterIndex.size() - 1] = ClusterReads; if(overlapcluster){ //add extra block if there is at least one read overlap with the next block ClusterIndex.push_back((cds_word)-1); if(IndexClusterToLines != NULL) IndexClusterToLines->push_back(numberOfLines); ClusterOverlap.push_back(overlapcluster); } fileSeq.close(); huffA = new Huffman(occ_notA, 249, true); huffC = new Huffman(occ_notC, 249, true); huffG = new Huffman(occ_notG, 249, true); huffT = new Huffman(occ_notT, 249, true); SaveValue(fp, ROW); cout << "ClusterSize: " << ClusterOverlap.size() << endl; cds_word novacio = 0; for(cds_word i = 0; i < ClusterIndex.size() ; i++){ if(ClusterIndex[i] != (cds_word)-1) novacio++; } cout << "No vacio: " << novacio << endl; index = &ClusterIndex[0]; //Index data if(ClusterIndex.size() != ClusterOverlap.size()) cout << "Error: Number of blocks created is not correct" << endl; SaveValue(fp, (cds_word)ClusterIndex.size()); index_pos = fp.tellp(); SaveValue(fp, index, ClusterIndex.size()); SaveValue(fp, variableSize); //if(variableSize){ index = &ClusterOverlap[0]; SaveValue(fp, index, ClusterOverlap.size()); //} cds_word Variables[6]; Variables[0] = numberOfLinesNR; Variables[1] = numberOfLines; Variables[2] = sizeLine.size(); Variables[3] = preSeqLength; Variables[4] = (cds_word)(RNames.size()); Variables[5] = IndexRate; SaveValue(fp, Variables, 6); SaveValue(fp, &sizeLine[0], sizeLine.size()); for(cds_word i = 0; i < RNames.size(); i++){ SaveValue(fp, (cds_word)(RNames[i].length())); SaveValue(fp, (char *)(RNames[i].c_str()), RNames[i].length()); SaveValue(fp, RNamesCluster[i]); } huffA->Save(fp); huffC->Save(fp); huffG->Save(fp); huffT->Save(fp); init_preseq = fp.tellp(); init_preseq += 3 * sizeof(size_t); SaveValue(fp, init_preseq); SaveValue(fp, init_seq); SaveValue(fp, end_seq); buffer = init_buffer(); buffer_use = 0; CompressPressumeSeq(fp, &buffer, &buffer_use); init_seq = fp.tellp(); //RE-READ SAM FILE AND CREATE NEW FILE ComputeCSeq(SamFile, fp, SamOrRps); end_seq = fp.tellp(); fp.seekp(index_pos); index = &ClusterIndex[0]; SaveValue(fp, index, ClusterIndex.size()); fp.seekp(init_preseq - 2 * sizeof(size_t)); SaveValue(fp, init_seq); SaveValue(fp, end_seq); remove(tmp_name.c_str()); fp.seekp(end_seq); }
int Logger::lengthFileLog() { fileLog.seekp(0, ios::end); int fileLogSize = static_cast<int>(fileLog.tellp()); return fileLogSize; }