当前位置: 首页>>代码示例>>C++>>正文


C++ FileOutputStream类代码示例

本文整理汇总了C++中FileOutputStream的典型用法代码示例。如果您正苦于以下问题:C++ FileOutputStream类的具体用法?C++ FileOutputStream怎么用?C++ FileOutputStream使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了FileOutputStream类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: TEST

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;
}
开发者ID:FikiHafana,项目名称:djondb,代码行数:27,代码来源:main.cpp

示例2: MergeStreams

void MergeStreams(FileInputStream * in1, FileInputStream * in2, char * outfile) {
FileOutputStream * outStream = NULL;
try {
	int nbytes;
	char buffer[1];
    outStream = new FileOutputStream(outfile);
    
	while ((nbytes = (in1->read(buffer, 1)) != -1)) {
		outStream->write(buffer, nbytes);
	    }

	while ((nbytes = (in2->read(buffer, 1)) != -1)) {
		outStream->write(buffer, nbytes);
	    }

	delete outStream;
    }
catch (IOException & err) {
	err.Display();
	cout<<"Deleting dynamic outStream object"<<endl;
	delete outStream;
    throw FileNotFoundException(outfile);
    }
catch (Xception & err) {
	err.Display();
	cout<<"Deleting dynamic FileOutputStream object"<<endl;
	delete outStream;
    throw FileNotFoundException(outfile);
    }
}
开发者ID:rortian,项目名称:oldjava,代码行数:30,代码来源:ExceptionDemo2.cpp

示例3: String

const String LumaPlug::LumaDocument::saveDocument (const File& file)
{
	if (file.exists())
	{
		bool deleteSuccess = file.deleteFile();
		if (!deleteSuccess)
		{
			return String("Delete of existing file failed!");
		}
	}

	FileOutputStream* stream = file.createOutputStream();
	if (!stream)
	{
		return String("Failed to obtain output stream to save file!");
	}
	String scriptText = plug->getScriptText();
	if (scriptText.length() > 0)
	{
		bool writeSuccess = stream->write(scriptText.toUTF8(), scriptText.length());
		if (!writeSuccess)
		{
			return String("Write to output stream failed!");
		}
		stream->flush();
	}

    return String::empty;
}
开发者ID:georgekrueger,项目名称:Luma,代码行数:29,代码来源:LumaPlug.cpp

示例4: f

// protected
void
FileOutputStreamTestCase::write (void)
{
    File f (TEST_FILE_NAME);
    if (f.exists ())
        f.remove ();

    FileOutputStream out (TEST_FILE_NAME, CREATE_NEW_MODE);
    const char* str = "Test line 1\r\nTest line 2\r\nTest line 3";
    out.write ((const unsigned char*)str, strlen (str));
    out.close ();


    File ff (TEST_FILE_NAME);
    CPPUNIT_ASSERT (ff.getLength () == strlen (str));


    File filer (TEST_FILE_NAME1);
    if (filer.exists ())
        filer.remove ();

    FileOutputStream fout5(TEST_FILE_NAME1, APPEND_MODE);
    String s2 = "test line";
    fout5.write ((unsigned char*)s2.getCStr (), s2.getLength ());
    File filetest (TEST_FILE_NAME1);
    CPPUNIT_ASSERT (filetest.getLength () == s2.getLength ());
    fout5.close ();

}
开发者ID:hanxin1987216,项目名称:DTL,代码行数:30,代码来源:fileoutputtc.cpp

示例5: TEST

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;
	}
}
开发者ID:FikiHafana,项目名称:djondb,代码行数:35,代码来源:testIndexP.cpp

示例6: audioFileName

 // =================================================================================================================
 bool DiskSampleRecorder::reserveDiskSpace(String outDir, int64 lengthInBytes)
 {
	String		audioFileName(outDir);
	File*		tempDataFile;
	Time		now;

	if ( !audioFileName.endsWith(File::separatorString))
		audioFileName += File::separatorString;

	for (int i=0; i < processorOutputs; i++)
	{
		now = Time::getCurrentTime();

		tempDataFile = new File(audioFileName + "channel" + String::formatted("%.2d", i) + ".dat");

		if (*tempDataFile == File::nonexistent)
		{
			mchaRecordPlayer->logError( L"Failed to reserve disk space for data file:\t" + tempDataFile->getFullPathName() );
			delete tempDataFile;
			return false;		
		}
		else
		{
			FileOutputStream* tempStream = tempDataFile->createOutputStream();
			if (tempStream == NULL)
			{
				mchaRecordPlayer->logError( L"Failed to create output stream for data file:\t" + tempDataFile->getFullPathName() );
				delete tempStream;
				delete tempDataFile;
				return false;
			}
			else
			{
				if (!tempStream->setPosition(lengthInBytes))
				{
					mchaRecordPlayer->logError( L"Failed to position output stream for data file:\t" + tempDataFile->getFullPathName() + ". Insufficient disk space?" );
					delete tempStream;
					delete tempDataFile;
					return false;				
				}
				else
				{
					int zeroByte = 0;
					tempStream->write( (void *) &zeroByte, 1);
					tempStream->flush();
				}
			}
			RelativeTime timeDelay = Time::getCurrentTime() - now;
			mchaRecordPlayer->dbgOut( "\tReserving disk space for\t" + tempDataFile->getFullPathName() + "\t" + String(lengthInBytes) + " bytes\t" + String(timeDelay.inSeconds())+ " s elapsed." );
			delete tempStream;
			delete tempDataFile;			
		}

	}
	
	return true;
 }
开发者ID:RomanKosobrodov,项目名称:mcha,代码行数:58,代码来源:DiskSampleRecorder.cpp

示例7: Save

int Doc::Save( ArrayPtrVoid params )
{  
    // param 0: output stream
    FileOutputStream *output = static_cast<FileOutputStream*>(params[0]);         
    if (!output->WriteDoc( this )) {
        return FUNCTOR_STOP;
    }
    return FUNCTOR_CONTINUE;
}
开发者ID:raffazizzi,项目名称:verovio,代码行数:9,代码来源:doc.cpp

示例8: appendToFile

static void appendToFile (const File& f, const String& s)
{
    if (f.getFullPathName().isNotEmpty())
    {
        FileOutputStream out (f);

        if (! out.failedToOpen())
            out << s << newLine;
    }
}
开发者ID:AlessandroGiacomini,项目名称:pyplasm,代码行数:10,代码来源:juce_PerformanceCounter.cpp

示例9: saveDocument

    Result saveDocument (const File& file) override
    {
        // attempt to save the contents into the given file
        FileOutputStream os (file);

        if (os.openedOk())
            os.writeText (editor.getText(), false, false);

        return Result::ok();
    }
开发者ID:Xaetrz,项目名称:AddSyn,代码行数:10,代码来源:MDIDemo.cpp

示例10: toJSON

void ApplicationSettingsFile::SaveAs(File file)
{
	var json = toJSON();
	FileOutputStream *outputStream = file.createOutputStream();
	outputStream->setPosition(0);
	JSON::writeToStream(*outputStream, json);
	outputStream->flush();
	delete outputStream;
	outputStream = nullptr;
}
开发者ID:Nimgoble,项目名称:GlobalHooksTest,代码行数:10,代码来源:ApplicationSettingsFile.cpp

示例11: ff

// protected
void
FileOutputStreamTestCase::close (void)
{
    File ff (TEST_FILE_NAME);
    if (ff.exists () == false)
        ff.create ();

    FileOutputStream fout (TEST_FILE_NAME, OPEN_MODE);
    CPPUNIT_ASSERT (fout.seek (1, BEGIN_ORIGIN) == 1);
    fout.close ();

}
开发者ID:hanxin1987216,项目名称:DTL,代码行数:13,代码来源:fileoutputtc.cpp

示例12: in

Result ZipFile::uncompressEntry (int index, const File& targetDirectory, bool shouldOverwriteFiles)
{
    auto* zei = entries.getUnchecked (index);

   #if JUCE_WINDOWS
    auto entryPath = zei->entry.filename;
   #else
    auto entryPath = zei->entry.filename.replaceCharacter ('\\', '/');
   #endif

    if (entryPath.isEmpty())
        return Result::ok();

    auto targetFile = targetDirectory.getChildFile (entryPath);

    if (entryPath.endsWithChar ('/') || entryPath.endsWithChar ('\\'))
        return targetFile.createDirectory(); // (entry is a directory, not a file)

    ScopedPointer<InputStream> in (createStreamForEntry (index));

    if (in == nullptr)
        return Result::fail ("Failed to open the zip file for reading");

    if (targetFile.exists())
    {
        if (! shouldOverwriteFiles)
            return Result::ok();

        if (! targetFile.deleteFile())
            return Result::fail ("Failed to write to target file: " + targetFile.getFullPathName());
    }

    if (! targetFile.getParentDirectory().createDirectory())
        return Result::fail ("Failed to create target folder: " + targetFile.getParentDirectory().getFullPathName());

    {
        FileOutputStream out (targetFile);

        if (out.failedToOpen())
            return Result::fail ("Failed to write to target file: " + targetFile.getFullPathName());

        out << *in;
    }

    targetFile.setCreationTime (zei->entry.fileTime);
    targetFile.setLastModificationTime (zei->entry.fileTime);
    targetFile.setLastAccessTime (zei->entry.fileTime);

    return Result::ok();
}
开发者ID:COx2,项目名称:JUCE_JAPAN_DEMO,代码行数:50,代码来源:juce_ZipFile.cpp

示例13: file

// protected
void
FileOutputStreamTestCase::flush (void)
{
    File file (_T("testflush"));
    if (file.exists ())
        file.remove ();

    FileOutputStream fout (_T("testflush"), CREATE_NEW_MODE);

    fout.write ((unsigned char*)"1", 1);
    fout.flush ();
    CPPUNIT_ASSERT (file.getLength () == 1);


    fout.close ();
    file.remove ();
}
开发者ID:hanxin1987216,项目名称:DTL,代码行数:18,代码来源:fileoutputtc.cpp

示例14: Contains

HRESULT CFileHelper::WriteText(LPCTSTR path, LPCTSTR text)
{
	BOOL exists = FALSE;

	HRESULT hr = Contains(path, exists);
	if(FAILED(hr)) return hr;

	if( !exists)
	{
		String folder ;
		if(SUCCEEDED( GetParentFolder(path, folder)))
		{
			hr = CreateFolder(folder.c_str());	
			if(FAILED(hr)) return hr;
		}
	}	

	FileOutputStream ofs;

	ofs.imbue(locale("chs"));

	ofs.open(path);

	if(!ofs.is_open()) return E_FAIL;

	ofs.clear();

	ofs.write(text, STRLEN(text)/* *sizeof(TCHAR)*/);

	ofs.close();

	return S_OK;
}
开发者ID:bestustc,项目名称:MyTutorial,代码行数:33,代码来源:FileHelper.cpp

示例15: String

bool Tunefish4AudioProcessor::saveProgram(eU32 index)
{
    String path = pluginLocation +
    File::separatorString + String("tf4programs") + File::separatorString +
    String("program") + String(index) + String(".txt");

    File file(path);
    file.deleteFile();
    FileOutputStream *stream = file.createOutputStream();
    if (!stream)
        return false;

    stream->writeText(programs[index].getName(), false, false);
    stream->writeText("\r\n", false, false);

    for(eU32 i=0;i<TF_PARAM_COUNT;i++)
    {
        stream->writeText(TF_NAMES[i], false, false);
        stream->writeText(";", false, false);
        stream->writeText(String(programs[index].getParam(i)), false, false);
        stream->writeText("\r\n", false, false);
    }

    eDelete(stream);
    return true;
}
开发者ID:kzantow,项目名称:tunefish,代码行数:26,代码来源:PluginProcessor.cpp


注:本文中的FileOutputStream类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。