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


C++ FileOutputStream::flush方法代码示例

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


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

示例1: 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

示例2: ff

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

    FileOutputStream fout (TEST_FILE_NAME, OPEN_MODE);
    String ss = "dflajdkjasldjfaksldjfsalkdjalksdjadflajdkjasldjfaksldjfsalkdjalksdjadflajdkjasldjfaksldjfsalkdjalksdjadflajdkjasldjfaksldjfsalkdjalksdjadflajdkjasldjfaksldjfsalkdjalksdja sd";
    fout.write ((unsigned char *)ss.getCStr (), ss.getLength ());
    fout.flush ();

    CPPUNIT_ASSERT_THROW (fout.seek (-1, BEGIN_ORIGIN), Exception);
    CPPUNIT_ASSERT (fout.seek (3, BEGIN_ORIGIN) == 3);
    CPPUNIT_ASSERT (fout.seek (21, BEGIN_ORIGIN) == 21);
    CPPUNIT_ASSERT (fout.seek (38, BEGIN_ORIGIN) == 38);

    CPPUNIT_ASSERT (fout.seek (-7, CURRENT_ORIGIN) == 31);
    CPPUNIT_ASSERT (fout.seek (2, CURRENT_ORIGIN) == 33);
    CPPUNIT_ASSERT_THROW (fout.seek (-73, CURRENT_ORIGIN), Exception);
    CPPUNIT_ASSERT (fout.seek (24, CURRENT_ORIGIN) == 57);
    CPPUNIT_ASSERT (fout.seek (24, CURRENT_ORIGIN) == 81);

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

示例3: reserveDiskSpace

 // =================================================================================================================
 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

示例4: SaveAs

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

示例5: 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


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