void write_array(ofstream &out_file, const unsigned char *array, size_t array_size, uint_least64_t half_key_length, bool decryption) { if (!decryption) { for (size_t i = array_size; i < half_key_length; ++i) { out_file.put('\0'); } } for (size_t i = decryption ? 1 : 0; i < array_size; ++i) { out_file.put(static_cast<char>(array[i])); } }
bool Serializer::writeChar(ofstream &outfile, char write) { outfile.put(write); if (!outfile.good()) return false; return true; }
//----------------------------------------------------------------------------- void PDCFileWriter::writePDCHeader(ofstream &outfile) { //create temporary versions of the variables to byte-swap int temp_formatVersion = getFormatVersion(); int temp_byteOrder = getByteOrder(); int temp_extra1 = getExtra1(); int temp_extra2 = getExtra2(); int temp_numParticles = getParticleCount(); int temp_numAttributes = getAttributeCount(); //do swap of byte order swapInt((char*) &temp_formatVersion); swapInt((char*) &temp_byteOrder); swapInt((char*) &temp_extra1); swapInt((char*) &temp_extra2); swapInt((char*) &temp_numParticles); swapInt((char*) &temp_numAttributes); //write out to file for(int i=0;i<4;i++) { outfile.put( m_format[i]); } outfile.write((char*) &temp_formatVersion, sizeof(int)); outfile.write((char*) &temp_byteOrder, sizeof(int)); outfile.write((char*) &temp_extra1, sizeof(int)); outfile.write((char*) &temp_extra2, sizeof(int)); outfile.write((char*) &temp_numParticles, sizeof(int)); outfile.write((char*) &temp_numAttributes, sizeof(int)); }
void put16(ofstream &ofs, unsigned i) { char a, b; a = i>>8; // printf("store (%4X) %4X\n", i, a); ofs.put((char)a); ofs.put((char)i); }
//24bits per pixel bitmap static bool write_bitmap24(unsigned char *bitmap) { char padding_byte=0; int k=0; for (int i=0; i<h;i++){ for (int j=0; j<original_w*3; j++){ fout.put(bitmap[k]); k++; } for (int p=0; p<padbyte_count;p++) fout.put(padding_byte); } return 1; }
//black and white bitmap static bool write_bitmap(char *bitmap) { int i=0; for (i=0; i<sz;i++) fout.put(bitmap[i]); return 1; }
/** This function handles the decoding of the * input file. It will convert the encoded file * to it's original condition. * * @params: reference to input & output streams */ void decode(BitInputStream* in, ofstream& out) { int symbol = 0; for (auto i = 0; i < numBytes; ++i) { symbol = huffman->decode(*in); out.put((char)symbol); out.flush(); } }
void FileStream() { char c; while(infile.get(c)) { outfile.put(c); } }
void FileClass::doFilter(ifstream &input, ofstream &output) { char letter; while(!input.eof()) // double checks, { input.get(letter); if (!(input)) break; // this is where the loop actually ends after .get reaches the eof output.put(transform(letter)); } }
void FileClass::doFilter(ifstream &input, ofstream &output) { char letter; while(!input.eof()) { input.get(letter); if (!(input)) break; output.put(transform(letter)); } }
void Tone::writeSample(int value, ofstream &out) { if(m_bitsPerSample == 16) { int16_t sample = uint16toLE(value); out.write((char *)&sample, 2); } else { out.put(value); } }
//transfer function uses the virtual transform void AbstractTrans::transfer() { char ch; char transCh; inFile.get(ch); while(!inFile.fail()) { transCh = transform(ch); outFile.put(transCh); inFile.get(ch); } }
//******************************************************************************** // Encrypt function uses the virtual transform member function to transform * // individual characters. * //******************************************************************************** void Encryption::encrypt() { char ch; char transCh; inFile.get(ch); while (!inFile.fail()) { transCh = transform(ch); outFile.put(transCh); inFile.get(ch); } }
Context handle_code(ifstream& inFile, ofstream& outFile) { char ch; while(inFile.get(ch)) { switch(ch) { case '/': if(!inFile.get(ch)) { outFile.put('/'); return file_end; } else { if(ch == '*') return c_comment; else if(ch == '/') return cpp_comment; else { cout << "Context = / followed by reg. text, ch = " << ch << endl; outFile << keyWord; keyIndex = 0; strncpy(keyWord,"\0", 64); outFile.put('/'); inFile.putback(ch); break; } } case '\"' : return string_literal; case '\'' : return char_literal; case '\n' : return newline; default: { keyMatch(ch, outFile); } } } return file_end; }
void copy() { if( optAttributesOnly == false ) { char c; while( inputFile.get( c ) ) { outputFile.put( c ); } } }
void misspell(ifstream &in, ofstream &out, int fact) { char ch, next; int index, lower; while (! in.eof()) { ch = in.get(); if ((random(fact) != 0) || ! isalpha(ch)) { out.put(ch); cout.put(ch); } else { lower = islower(ch); index = tolower(ch) - 'a'; ch = table[index].first; next = table[index].next; if (! lower) { ch = toupper(ch); next = toupper(next); }; if (ch) { out.put(ch); cout.put(ch); }; if (next) { out.put(next); cout.put(next); }; }; // if ((random... }; // while ( ! in... }
void space_remover(ifstream& in_stream, ofstream& out_stream) { char current_char; bool shouldContinue = true; do { in_stream.get(current_char); if (current_char == ' ') { out_stream.put(current_char); do { in_stream.get(current_char); } while (current_char == ' '); out_stream.put(current_char); } else if (!in_stream.eof()) { out_stream.put(current_char); } else { shouldContinue = false; } } while (shouldContinue == true); }
// Literals (char, string) // Make sure that <,>, etc are escaped inside literals! void handle_literal(char delimiter, ifstream& inFile, ofstream& outFile) { outFile << "<font color=\"gray\">"; outFile.put(delimiter); char ch; while(inFile.get(ch)) { if(ch == delimiter) { outFile.put(ch); break; } else if(ch == '\\'){ outFile.put(ch); // TEST inFile.get(ch) && outFile.put(ch); } else outputChar(ch, outFile); } outFile << "</font>"; }
inline void WritePara(ofstream& to) { int m,w,n; m = 0; if (first) first=0; else to.put('\n'); while (m<i) { w = Best[m]; n = (i-w) - m; for (int j=1; j< n; j++) { for (int k=0; k< WordLengths[m+j]; k++) to.put(Words[m+j][k]); to.put(' '); }; for (int k=0; k< WordLengths[m+n]; k++) to.put(Words[m+n][k]); to.put('\n'); m = i-w; } }
void Encryption::decrypt() { char ch; char transCh; inFile.get(ch); while(!inFile.fail()) { transCh = untransform(ch); outFile.put(transCh); inFile.get(ch); } inFile.clear(); inFile.seekg(0); }
void processing(ifstream& inFile, ofstream& outFile) { //variable declarations char letter; double number, avg, sum(0); //sets precision and decimal place outFile.setf(ios::fixed); outFile.setf(ios::showpoint); outFile.precision(2); outFile << "********************************************" << endl << "Student Name: "; //outputs name to result.txt while(letter != '\n') { inFile.get(letter); outFile.put(letter); } outFile << "Test Scores: "; //outputs scores and finds their sum inFile >> number; while(! inFile.eof( )) { sum += number; outFile << number << setw(8); inFile >> number; } //calculates average avg = sum / 5.0; outFile << endl << "Average Score: " << avg << endl << "********************************************" << endl; }
//Modify file content function bool modelA::modifyContFile(ofstream mdfos,unsigned int startPos,unsigned int endPos,string newContent) { if(endPos<startPos) return false; else { //Move ofstream pointer to end position mdfos.seekp(endPos,ios_base::beg); //Delete old content for(int i=0;i<int(endPos-startPos);i++) mdfos.put(char(8)); //Write new content mdfos<<newContent<<flush; //Exit and go to begin mdfos.clear(); mdfos.seekp(0,ios_base::beg); } return true; }
/** *a function that writes the bits to the output file *takes an intger represent the bit value to be writted as argument *An of stream objects that has an opened file assocated with it is also required by refrence *a bit value of -1 indicated that the buffer be filled with required padding bits and then written */ void Huffman::Output1Bit(int bit,ofstream& out) { if (BitCounter == 8 || bit == -1) { while (BitCounter <8)//for padding bits { BitContainer=BitContainer << 1; BitCounter += 1; } out.put(BitContainer); //out.write(reinterpret_cast<const char *>(&BitContainer),sizeof(unsigned char)); BitCounter = 0; BitContainer=BitContainer << 7; } if(bit==-1) return; BitContainer = (BitContainer << 1) | bit; BitCounter++; wrotes++; }
/*********************************************************************** * This function will allow reading and writing to input and output * files. It uses a call to a virtual function "transform()" to allow * its use as a file filter. **********************************************************************/ void fileFilter::doFilter(ifstream &in, ofstream &out) { char ch; // Variable to hold the input character char transCh; // Varialbe to hold the output character // Get first character from input file in.get(ch); // Continue to get and operate on characters in file until EOF reached while (!in.fail()) { // Call virtual transform() function to perform desired task based on class of object transCh = transform(ch); // Write operated on character to output file out.put(transCh); // Get next character in input file in.get(ch); } }
void decodingText(int numOfChars, ofstream & writeFile, ifbitstream & readArch, Node* root){ Node * current = root; while (numOfChars > 0){ int bit = readArch.readBit(); if(bit == 1){ current = current->right; } else { current = current->left; } if(isLeaf(current)){ writeFile.put(current->value); current = root; --numOfChars; } } readArch.close(); writeFile.close(); }
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); }
int outputChar(char ch, ofstream& outFile) { if(ch == '>') { outFile << ">"; return 0; } else if (ch == '<') { outFile << "<"; return 0; } else if(ch == '\n') { outFile << "\n"; return 0; } else if(ch == '&') { outFile << "&"; return 0; } else { outFile.put(ch); return 0; } }
// запись строки в файл void WriteWord(ofstream& f, char* word) { int i = 0; while (word[i] != '\0') { f.put(word[i++]); } }
void IsoFile::uncompress(ifstream &isofile, ofstream &outfile, unsigned long long offset, unsigned long filesize) { const unsigned char zisofs_magic[8] = { 0x37, 0xE4, 0x53, 0x96, 0xC9, 0xDB, 0xD6, 0x07 }; struct mkzftree_file_header { char magic[8]; char uncompressed_len[4]; unsigned char header_size; unsigned char block_size; char reserved[2]; }; struct mkzftree_file_header hdr; isofile.seekg(offset); if (isofile.good()) { isofile.read((char *)&hdr,sizeof(hdr)); if (memcmp(&hdr.magic,zisofs_magic,sizeof(zisofs_magic))) { SEISCOMP_INFO("Maybe file is not compressed (with mkzftree); simply it will be copied!"); isofile.seekg(offset); char c; while (filesize) { isofile.get(c); outfile.put(c); --filesize; } } else { const short PTRSIZE = 4; unsigned long bsize = 1 << hdr.block_size; unsigned long csize, startptr, endptr; unsigned long long ptrpos = isofile.tellg(); char *inbuf, *outbuf; try { outbuf = new char[bsize]; } catch (std::bad_alloc &) { throw ArchiveException("Memory allocation failed"); } do { startptr = isofile.get() + (isofile.get() << 8) + (isofile.get() << 16) + (isofile.get() << 24); endptr = isofile.get() + (isofile.get() << 8) + (isofile.get() << 16) + (isofile.get() << 24); csize = endptr - startptr; try { inbuf = new char[csize]; } catch (std::bad_alloc &) { delete[] outbuf; throw ArchiveException("Memory allocation failed"); } ptrpos += PTRSIZE; isofile.seekg(startptr+offset); isofile.read(inbuf,csize); if (::uncompress((Bytef *)outbuf,(uLongf *)&bsize,(Bytef *)inbuf,csize) != Z_OK) { delete[] inbuf; delete[] outbuf; throw ArchiveException("Uncompressing file using zlib's uncompress() failed"); } if (bsize != (unsigned long)(1 << hdr.block_size) && endptr != filesize) { delete[] inbuf; delete[] outbuf; throw ArchiveException("Incorrect number of uncompressed bytes"); } outfile.write(outbuf,bsize); if (!outfile.good()) { delete[] inbuf; delete[] outbuf; throw ArchiveException("Writing uncompressed file failed"); } delete[] inbuf; isofile.seekg(ptrpos); } while (filesize != endptr); delete[] outbuf; } } else SEISCOMP_ERROR("Reading isofile failed!"); }
void WriteCvMatBin(ofstream &os, CvMat *mat, CString name /*= ""*/) { if (!name.IsEmpty()) WriteStringLine(os, name); os.write((char*)mat->data.ptr, mat->step * mat->rows); os.put('\n'); }