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


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

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


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

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

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

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

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

示例5: WriteText

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

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

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

示例8: convert

void HeightMap::convert(const String& path) {
	FileInputStream* reader = NULL;
	try {
		reader = new FileInputStream(new File(path));
	} catch (...) {
		System::out << "could not open reader" << endl;

		exit(1);
	}

	FileOutputStream* writer = NULL;

	try {
		writer = new FileOutputStream(new File("converted_" + path));
	} catch (...) {
		System::out << "could not open writer" << endl;
		exit(1);
	}

	//FileOutputStream* writer = new FileOutputStream(new File("converted_" + path));

	byte emptybuffer[PLANEWIDTH * HEIGHTSIZE];

	for (int i = 0; i < PLANEWIDTH * HEIGHTSIZE; ++i)
		emptybuffer[i] = 0;

	// first 2 lines
	for (int i = 0; i < 2 * 64; ++i) {
		for (int j = 0; j < PLANEWIDTH; ++j)
			writer->write(emptybuffer, PLANEWIDTH * HEIGHTSIZE);
	}

	int planeIndexX = 2;
	int planeIndexY = 2;

	// inner 60 lines
	for (int i = 0; i < 60; ++i) {
		// 2 beginning plane
		for (int j = 0; j < 2 * PLANEWIDTH; ++j)
			writer->write(emptybuffer, PLANEWIDTH * HEIGHTSIZE);

		// inner 60 planes
		for (int j = 0; j < 60; ++j) {
			System::out << "\r writing(" << planeIndexX << ", " << planeIndexY << ")";

			float plane[PLANEWIDTH * PLANEWIDTH];
			readPlaneForConversion(reader, plane, planeIndexX - 2, planeIndexY - 2);

			writer->write((byte*) plane, PLANEWIDTH * PLANEWIDTH * HEIGHTSIZE);

			++planeIndexX;
		}

		planeIndexX = 2;
		++planeIndexY;

		// 2 ending plane
		for (int j = 0; j < 2 * PLANEWIDTH; ++j)
			writer->write(emptybuffer, PLANEWIDTH * HEIGHTSIZE);
	}

	//last 2 lines
	for (int i = 0; i < 2 * 64; ++i) {
		for (int j = 0; j < PLANEWIDTH; ++j)
			writer->write(emptybuffer, PLANEWIDTH * HEIGHTSIZE);
	}

	writer->close();

	delete writer;
	delete reader;
}
开发者ID:JigglyPoofSWG,项目名称:BSS,代码行数:72,代码来源:HeightMap.cpp

示例9: main

int main( char inNumArgs, char **inArgs ) {

	if( inNumArgs < 2 ) {
		usage( inArgs[0] );
		}
	if( inNumArgs > 3 ) {
		usage( inArgs[0] );
		}
	char useFile = true;
	if( inNumArgs != 3 ) {
		useFile = false;
		}

	long port;
	int numRead = sscanf( inArgs[1], "%d", &port );

	if( numRead != 1 ) {
		printf( "port number must be a valid integer:  %s\n", inArgs[2] );
		usage( inArgs[0] );
		}

	File *outFile;
	FileOutputStream *outStream;

	if( useFile ) {
		outFile = new File( NULL, inArgs[2],
							strlen( inArgs[2] ) );
		
		outStream = new FileOutputStream( outFile );
		}
   
	SocketServer *server = new SocketServer( port, 1 );
	
	printf( "listening for a connection on port %d\n", port );
	Socket *sock = server->acceptConnection();

	if( sock == NULL ) {
		printf( "socket connection failed\n" );
		return( 1 );
		}
	printf( "connection received\n" );
	
	
	SocketStream *inStream = new SocketStream( sock );

	
	unsigned long checksum = 0;

	unsigned char *buffer = new unsigned char[ BUFFER_SIZE ];
	

	numRead = BUFFER_SIZE;
	int numWritten = BUFFER_SIZE;
	
	while( numWritten == numRead && numRead == BUFFER_SIZE ) {

		// read a buffer full of data from standard in
		numRead = inStream->read( buffer, BUFFER_SIZE );

		// add the buffer to our checksum
		for( int i=0; i<numRead; i++ ) {
			checksum += buffer[i];
			}


		if( useFile ) {
			// write the buffer out to our file stream
			numWritten = outStream->write( buffer, numRead );
			}
		else {
			// write to std out
			numWritten = fwrite( buffer, 1, numRead, stdout );
			}
		}

	

	if( numRead != numWritten ) {
		printf( "file output failed\n" );
		}
	

	
	printf( "checksum = %d\n", checksum );


	delete sock;
	delete server;
	delete inStream;
	if( useFile ) {
		delete outStream;
		delete outFile;
		}
	
	delete [] buffer;
	
	return 0;
	}
开发者ID:duralakun,项目名称:minorGems,代码行数:98,代码来源:netPipeReceiver.cpp

示例10: setUp

void FileInputStreamTestCase::setUp (void)
{
	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));
}
开发者ID:hanxin1987216,项目名称:DTL,代码行数:6,代码来源:fileinputtc.cpp


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