bool YUVPixelDataGenerator (uint8_t* pPointer, int32_t iWidth, int32_t iHeight, int32_t iStride) { #define SRC_FRAME_WIDTH (160) #define SRC_FRAME_HEIGHT (96) if (SRC_FRAME_WIDTH - iWidth <= 0 || SRC_FRAME_HEIGHT - iHeight <= 0) { return false; } const int32_t kiFrameSize = SRC_FRAME_WIDTH * SRC_FRAME_HEIGHT; BufferedData sBuf; sBuf.SetLength (kiFrameSize); if (sBuf.Length() != (size_t)kiFrameSize) { return false; } FileInputStream fileStream; if (!fileStream.Open ("res/CiscoVT2people_160x96_6fps.yuv")) { return false; } if (fileStream.read (sBuf.data(), kiFrameSize) == kiFrameSize) { int32_t iStartPosX = rand() % (SRC_FRAME_WIDTH - iWidth); int32_t iStartPosY = rand() % (SRC_FRAME_HEIGHT - iHeight); uint8_t* pSrcPointer = sBuf.data() + iStartPosX + iStartPosY * SRC_FRAME_WIDTH; uint8_t* pLocalPointer = pPointer; for (int j = 0; j < iHeight; j++) { memcpy (pLocalPointer, pSrcPointer, iWidth * sizeof (uint8_t)); pLocalPointer += iStride; pSrcPointer += SRC_FRAME_WIDTH; } return true; } return false; }
//============================================================================== static File resolveXDGFolder (const char* const type, const char* const fallbackFolder) { File userDirs ("~/.config/user-dirs.dirs"); StringArray confLines; if (userDirs.existsAsFile()) { FileInputStream in (userDirs); if (in.openedOk()) confLines.addLines (in.readEntireStreamAsString()); } for (int i = 0; i < confLines.size(); ++i) { const String line (confLines[i].trimStart()); if (line.startsWith (type)) { // eg. resolve XDG_MUSIC_DIR="$HOME/Music" to /home/user/Music const File f (line.replace ("$HOME", File ("~").getFullPathName()) .fromFirstOccurrenceOf ("=", false, false) .trim().unquoted()); if (f.isDirectory()) return f; } } return File (fallbackFolder); }
WadArchive(const char* name) : m_name(name), m_wadfile(name) { if(!m_wadfile.failed()) { wadinfo_t wadinfo; istream_read_wadinfo(m_wadfile, wadinfo); EWadVersion version = wad_version(wadinfo.identification); int miptexType = miptex_type_for_version(version); if(version != eNotValid) { m_wadfile.seek(wadinfo.infotableofs); for(int i = 0; i < wadinfo.numlumps; ++i) { char buffer[32]; lumpinfo_t lumpinfo; istream_read_lumpinfo(m_wadfile, lumpinfo); if(lumpinfo.type == miptexType) { strcpy(buffer, "textures/"); strcat(buffer, lumpinfo.name); strcat(buffer, type_for_version(version)); m_files.insert(files_t::value_type(buffer, wad_record_t(lumpinfo.filepos, lumpinfo.disksize, lumpinfo.size))); } } } } }
TEST(TestCommand, testShownamespacesCommand) { cout << "testShownamespacesCommand" << endl; FileOutputStream* fos = new FileOutputStream("test.dat", "wb"); CommandWriter* writer = new CommandWriter(fos); ShownamespacesCommand cmd; cmd.setDB("testdb"); writer->writeCommand(&cmd); fos->close(); delete fos; delete writer; FileInputStream* fis = new FileInputStream("test.dat", "rb"); CommandReader* reader = new CommandReader(fis); Command* resCmd = reader->readCommand(); EXPECT_TRUE(resCmd->commandType() == SHOWNAMESPACES); ShownamespacesCommand* sw = (ShownamespacesCommand*)resCmd; EXPECT_TRUE(sw->DB()->compare("testdb") == 0); fis->close(); delete resCmd; delete fis; delete reader; }
void CImageLabel::LoadImage(const char * pImageName) { if ( m_pTGA ) delete m_pTGA; // Load the Image m_pTGA = LoadTGAForRes(pImageName); if ( m_pTGA == NULL ) { // we didn't find a matching image file for this resolution // try to load file resolution independent char sz[256]; sprintf(sz, "%s/%s",gEngfuncs.pfnGetGameDirectory(), pImageName ); FileInputStream* fis = new FileInputStream( sz, false ); m_pTGA = new BitmapTGA(fis,true); fis->close(); } if ( m_pTGA == NULL ) return; // unable to load image int w,t; m_pTGA->getSize( w, t ); setSize( XRES (w),YRES (t) ); setImage( m_pTGA ); }
// protected void FileInputStreamTestCase::getFileName (void) { FileInputStream fin (TEST_FILE_NAME); CPPUNIT_ASSERT (fin.getFileName () == String (TEST_FILE_NAME)); fin.close (); }
// protected void FileInputStreamTestCase::close (void) { FileInputStream fin (TEST_FILE_NAME); CPPUNIT_ASSERT ((char)fin.read () == 'T'); fin.close (); }
MD5::MD5 (const File& file) { FileInputStream fin (file); if (fin.getStatus().wasOk()) processStream (fin, -1); else zerostruct (result); }
OutputStream& JUCE_CALLTYPE operator<< (OutputStream& stream, const File& fileToRead) { FileInputStream in (fileToRead); if (in.openedOk()) return stream << in; return stream; }
HRESULT CFileHelper::ReadAllText(LPCTSTR path, String & text) { FileInputStream ifs; ifs.imbue(locale("chs")); ifs.open(path,ifs.in); if(!ifs.is_open()) return E_FAIL; ifs.seekg(0,ifs.end); int size=ifs.tellg(); ifs.seekg(0); TCHAR * s=(TCHAR *)malloc(sizeof(TCHAR) * (size+1)); memset(s,0,sizeof(TCHAR)*(size+1)); ifs._Read_s(s,size ,sizeof(TCHAR) * size); ifs.close(); text = s; free(s); return S_OK; }
Image ImageFileFormat::loadFrom (const File& file) { FileInputStream stream (file); if (stream.openedOk()) { BufferedInputStream b (stream, 8192); return loadFrom (b); } return Image::null; }
Result ResourceFile::writeHeader (MemoryOutputStream& header) { const String headerGuard ("BINARYDATA_H_" + String (project.getProjectUID().hashCode() & 0x7ffffff) + "_INCLUDED"); header << "/* =========================================================================================" << getComment() << "#ifndef " << headerGuard << newLine << "#define " << headerGuard << newLine << newLine << "namespace " << className << newLine << "{" << newLine; bool containsAnyImages = false; for (int i = 0; i < files.size(); ++i) { const File& file = files.getReference(i); if (! file.existsAsFile()) return Result::fail ("Can't open resource file: " + file.getFullPathName()); const int64 dataSize = file.getSize(); const String variableName (variableNames[i]); FileInputStream fileStream (file); if (fileStream.openedOk()) { containsAnyImages = containsAnyImages || (ImageFileFormat::findImageFormatForStream (fileStream) != nullptr); header << " extern const char* " << variableName << ";" << newLine; header << " const int " << variableName << "Size = " << (int) dataSize << ";" << newLine << newLine; } } header << " // Points to the start of a list of resource names." << newLine << " extern const char* namedResourceList[];" << newLine << newLine << " // Number of elements in the namedResourceList array." << newLine << " const int namedResourceListSize = " << files.size() << ";" << newLine << newLine << " // If you provide the name of one of the binary resource variables above, this function will" << newLine << " // return the corresponding data and its size (or a null pointer if the name isn't found)." << newLine << " const char* getNamedResource (const char* resourceNameUTF8, int& dataSizeInBytes) throw();" << newLine << "}" << newLine << newLine << "#endif" << newLine; return Result::ok(); }
std::istream* FileStreamFactory::open(const Path& path) { File file(path); if (!file.exists()) throw FileNotFoundException(path.toString()); FileInputStream* istr = new FileInputStream(path.toString(), std::ios::binary); if (!istr->good()) { delete istr; throw OpenFileException(path.toString()); } return istr; }
TEST(testIndexP, testRecoverNames) { Logger* log = getLogger(NULL); std::set<std::string> keys; keys.insert("_id"); BPlusIndexP* index = new BPlusIndexP("testIndexNames"); index->setKeys(keys); FileInputStream* fis = new FileInputStream("names.txt", "r"); cout << "Adding names to the index" << endl; std::vector<std::string> names; int x = 0; while (true) { if (fis->eof()) { cout << "No more names" << endl; break; } if (x >= 100) { break; } x++; BSONObj o; std::string* name = fis->readString(); o.add("_id", name->c_str()); char* temp = strcpy(const_cast<char*>(name->c_str()), name->length()); index->add(o, djondb::string(temp, name->length()), 100); index->debug(); if (log->isDebug()) log->debug("==============================================================================="); names.push_back(*name); delete name; } index->debug(); delete index; cout << "Finding names from the index" << endl; index = new BPlusIndexP("testIndexNames"); index->setKeys(keys); index->debug(); for (std::vector<std::string>::iterator i = names.begin(); i != names.end(); i++) { std::string name = *i; BSONObj o; o.add("_id", name.c_str()); Index* idx = index->find(&o); ASSERT_TRUE(idx != NULL) << "_id " << name.c_str() << " not found"; ASSERT_TRUE(idx->key->has("_id")) << "Retrieved index for _id " << name.c_str() << " does not returned the _id"; EXPECT_TRUE(idx->key->getString("_id").compare(name) == 0) << "Recovered a wrong key, expected: " << name.c_str() << " and retrived: " << idx->key->getString("_id").c_str(); } delete index; }
//----------------------------------------------------------------------------- // Purpose: Loads a .tga file and returns a pointer to the VGUI tga object //----------------------------------------------------------------------------- BitmapTGA *LoadTGA( const char* pImageName ) { BitmapTGA *pTGA; char sz[256]; sprintf(sz, "%%d_%s", pImageName); // Load the Image FileInputStream* fis = new FileInputStream( GetVGUITGAName(sz), false ); pTGA = new BitmapTGA(fis,true); fis->close(); return pTGA; }
bool WavStream::open(const char *file_name) { FileInputStream *in; this->close(); in = new FileInputStream; if (!in->open(file_name) || !this->open(in)) { delete in; return false; } return true; }
void jojo_read (t_jojo *x, const File& aFile) { FileInputStream zipped (aFile); if (zipped.openedOk()) { // GZIPDecompressorInputStream unzipper (&zipped, false); StringArray myText (StringArray::fromLines (unzipper.readEntireStreamAsString())); for (int i = 0; i < myText.size(); ++i) { post ("%s", myText.getReference (i).toRawUTF8()); } // } }
// protected void FileInputStreamTestCase::ctors (void) { FileInputStream fin (TEST_FILE_NAME); File file (TEST_FILE_NAME); FileInputStream fin2(TEST_FILE_NAME, READ_SHARE); CPPUNIT_ASSERT_THROW (FileInputStream (TEST_FILE_NAME, WRITE_SHARE), Exception); fin2.close (); fin.close (); FileInputStream fin3(TEST_FILE_NAME, NONE_SHARE); CPPUNIT_ASSERT_THROW (FileInputStream (TEST_FILE_NAME, READ_SHARE), Exception); }
bool Tunefish4AudioProcessor::loadProgram(eU32 index) { String path = pluginLocation + File::separatorString + String("tf4programs") + File::separatorString + String("program") + String(index) + String(".txt"); File file(path); FileInputStream *stream = file.createInputStream(); if (!stream) return false; String name = stream->readNextLine(); programs[index].setName(name.toRawUTF8()); while(true) { String line = stream->readNextLine(); if (line.length() == 0) { eDelete(stream); return true; } StringArray parts; parts.addTokens(line, ";", String::empty); if (parts.size() == 2) { String key = parts[0]; eF32 value = parts[1].getFloatValue(); for(eU32 i=0;i<TF_PARAM_COUNT;i++) { if (key == TF_NAMES[i]) { programs[index].setParam(i, value); break; } } } } return true; }
FileIndexInfo DeepScanner::getFileIndexInfo(Error& error, FileInputStream& fis) { UInt32 iVolumeIndex, iFileIndexHi, iFileIndexLo; fis.getFileIndexInfo(error, iVolumeIndex, iFileIndexHi, iFileIndexLo); if (error) return FileIndexInfo(); else return FileIndexInfo(iVolumeIndex, iFileIndexHi, iFileIndexLo); }
// Play digitized wav from the wav file // suitable for very large wave file // // file_name - name of the wave file // // return: 1 - wav loaded and is playing // 0 - wav not played // OpenALAudio::yield() keeps on feeding data to it // int OpenALAudio::play_long_wav(const char *file_name, const DsVolume &vol) { FileInputStream *in = new FileInputStream; if (!this->wav_init_flag) return 0; MSG("play_long_wav(\"%s\", (%li, %li))\n", file_name, vol.ds_vol, vol.ds_pan); if (!in->open(file_name)) { delete in; return 0; } return this->play_long_wav(in, vol); }
void FileLogger::trimFileSize (int64 maxFileSizeBytes) const { if (maxFileSizeBytes <= 0) { logFile.deleteFile(); } else { const int64 fileSize = logFile.getSize(); if (fileSize > maxFileSizeBytes) { TemporaryFile tempFile (logFile); { FileOutputStream out (tempFile.getFile()); FileInputStream in (logFile); if (! (out.openedOk() && in.openedOk())) return; in.setPosition (fileSize - maxFileSizeBytes); for (;;) { const char c = in.readByte(); if (c == 0) return; if (c == '\n' || c == '\r') { out << c; break; } } out.writeFromInputStream (in, -1); } tempFile.overwriteTargetFileWithTemporary(); } } }
TEST(testIndexP, generateNames) { // this will avoid overriding previously generated names and keep consistent the results if (!existFile("names.txt")) { FileInputStream* fisNames = new FileInputStream("names.csv", "r"); const char* fullNames = fisNames->readFull(); FileInputStream* fisLastNames = new FileInputStream("last.csv", "r"); const char* fullLast = fisLastNames->readFull(); std::vector<string> names = split(fullNames, "\r"); cout << names.size() << endl; std::vector<string> lastNames = split(fullLast, "\r"); cout << lastNames.size() << endl; FileOutputStream* fos = new FileOutputStream("names.txt", "w+"); for (int x = 0; x < 10000000; x++) { int i = rand() % names.size(); std::string name = names.at(i); i = rand() % lastNames.size(); std::string lastName = lastNames.at(i); std::string fullName = name + " " + lastName; fos->writeString(fullName); } fos->close(); fisNames->close(); fisLastNames->close(); delete fos; delete fisNames; delete fisLastNames; } }
std::vector<std::string>* generateNames(int number) { // this will avoid overriding previously generated names and keep consistent the results FileInputStream* fisNames = new FileInputStream("names.csv", "r"); const char* fullNames = fisNames->readFull(); FileInputStream* fisLastNames = new FileInputStream("last.csv", "r"); const char* fullLast = fisLastNames->readFull(); std::vector<std::string> names = split(fullNames, "\r"); cout << names.size() << endl; std::vector<std::string> lastNames = split(fullLast, "\r"); cout << lastNames.size() << endl; std::vector<std::string>* generated = new std::vector<std::string>(); for (int x = 0; x < number; x++) { int i = rand() % names.size(); std::string name = names.at(i); i = rand() % lastNames.size(); std::string lastName = lastNames.at(i); std::string fullName = name + " " + lastName; generated->push_back(fullName); } fisNames->close(); fisLastNames->close(); delete fisNames; delete fisLastNames; return generated; }
bool InputSoundFile::openFromFile(const std::string& filename) { // If the file is already open, first close it close(); // Find a suitable reader for the file type m_reader = SoundFileFactory::createReaderFromFilename(filename); if (!m_reader) { err() << "Failed to open sound file \"" << filename << "\" (format not supported)" << std::endl; return false; } // Wrap the file into a stream FileInputStream* file = new FileInputStream; m_stream = file; m_streamOwned = true; // Open it if (!file->open(filename)) { close(); return false; } // Pass the stream to the reader SoundFileReader::Info info; if (!m_reader->open(*file, info)) { close(); return false; } // Retrieve the attributes of the open sound file m_sampleCount = info.sampleCount; m_channelCount = info.channelCount; m_sampleRate = info.sampleRate; return true; }
const String LumaPlug::LumaDocument::loadDocument (const File& file) { FileInputStream* stream = file.createInputStream(); juce::int64 size = stream->getTotalLength(); if (size <= 0) { return String("Input file size is zero!"); } MemoryBlock* buffer = new MemoryBlock(size+1, true); int bytesRead = stream->read(buffer->getData(), size); if (bytesRead != size) { return String("Bytes read from file differs from file size!"); } String text = String(static_cast<char*>(buffer->getData())); plug->newTextLoadedFromFile(text); delete buffer; return String::empty; }
bool convertToMP3() const { TemporaryFile tempMP3 (".mp3"); StringArray args2 (args); args2.add (tempWav.getFile().getFullPathName()); args2.add (tempMP3.getFile().getFullPathName()); DBG (args2.joinIntoString (" ")); if (runLameChildProcess (tempMP3, args2)) { FileInputStream fis (tempMP3.getFile()); if (fis.openedOk() && output->writeFromInputStream (fis, -1) > 0) { output->flush(); return true; } } return false; }
bool ResourceFile::writeHeader (MemoryOutputStream& header) { header << "/* =========================================================================================" << getComment() << "namespace " << className << newLine << "{" << newLine; bool containsAnyImages = false; for (int i = 0; i < files.size(); ++i) { const File& file = files.getReference(i); const int64 dataSize = file.getSize(); const String variableName (variableNames[i]); FileInputStream fileStream (file); if (fileStream.openedOk()) { containsAnyImages = containsAnyImages || (ImageFileFormat::findImageFormatForStream (fileStream) != nullptr); const String tempVariable ("temp_" + String::toHexString (file.hashCode())); header << " extern const char* " << variableName << ";" << newLine; header << " const int " << variableName << "Size = " << (int) dataSize << ";" << newLine << newLine; } } header << " // If you provide the name of one of the binary resource variables above, this function will" << newLine << " // return the corresponding data and its size (or a null pointer if the name isn't found)." << newLine << " const char* getNamedResource (const char* resourceNameUTF8, int& dataSizeInBytes) throw();" << newLine << "}" << newLine; return true; }
TEST(TestCommand, testShowdbs) { cout << "testShowdbs" << endl; FileOutputStream* fos = new FileOutputStream("test.dat", "wb"); CommandWriter* writer = new CommandWriter(fos); ShowdbsCommand cmd; writer->writeCommand(&cmd); fos->close(); delete fos; delete writer; FileInputStream* fis = new FileInputStream("test.dat", "rb"); CommandReader* reader = new CommandReader(fis); Command* resCmd = reader->readCommand(); EXPECT_TRUE(resCmd->commandType() == SHOWDBS); fis->close(); delete resCmd; delete fis; delete reader; }
Blob DeepScanner::getFileSHA(Error& error, FileInputStream& fis) { const int iBufSize = 4096; SHA512 sha; Buffer buf(iBufSize); while (true) { int iBytesRead = fis.read(error, buf.ptr(), iBufSize); if (error) return Blob(); sha.write(buf.ptr(), iBytesRead); if (iBytesRead < iBufSize) return sha.finish(); } }