本文整理汇总了C++中FileSystem::createFile方法的典型用法代码示例。如果您正苦于以下问题:C++ FileSystem::createFile方法的具体用法?C++ FileSystem::createFile怎么用?C++ FileSystem::createFile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileSystem
的用法示例。
在下文中一共展示了FileSystem::createFile方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: open
void FileStreamTfs::open()
{
try{
if (m_openMode == FileStream::ReadOnly){
if (m_fin != NULL) return;
m_fin = new InputStream;
m_fin->open(m_filename.c_str(), 0);
//cout <<"FileStreamTfs opens " <<m_filename <<" for read " <<endl;
}
else if (m_openMode == FileStream::Append){
//cout <<"FileStreamTfs opens " <<m_filename <<" for append " <<endl;
if (m_fout != NULL) return;
FileSystem fs;
if (!fs.existFile(m_filename)){
fs.createFile(m_filename, 1, 0);
}
m_fout = new AppendStream;
m_fout->open(m_filename.c_str(), 0);
}
}
catch (tfs::api::TFSException& e){
throw FSError(string("FileStreamTfs open file failed :") + m_filename + " error=>" + e.what());
}
}
示例2: exe
bool CommandPut::exe(FileSystem& fs, string parameter)
{
istringstream input(parameter);
string tfsPath;
string localPath;
int blocksize = -1; // add by fk
input >> localPath >> tfsPath >>blocksize; //get the parameters
if (blocksize == -1) blocksize = 1;
/**
* if the path is null, it puts nothing
*/
if(tfsPath == "" && localPath == ""){
cout << "USAGE: put <local_file> [<tfs_file>]" << endl;
cout << "EXAMPLE: put filename1" << endl;
cout << " put filename1 ." << endl;
cout << " put filename1 ./filename2" << endl;
cout << " put /home/abc/filename1" << endl;
cout << " put /home/abc/filename1 ./filename2" << endl;
return false;
}
// check local file
struct stat fileStat;
if (stat(localPath.c_str(), &fileStat) != 0){
cout << "Error: put: no such file " << localPath << endl;
return false;
}
bool bAbsolutePath;
string localDir;
string localFilename;
FilePath::split(localPath, bAbsolutePath, localDir, localFilename);
string tfsDir;
string tfsFilename;
FilePath::split(tfsPath, bAbsolutePath, tfsDir, tfsFilename);
if (!bAbsolutePath){ // reletive path
FilePath pathGenerator;
tfsDir = pathGenerator.getPath(m_currentDir, tfsDir);
tfsDir = pathGenerator.change(tfsDir); //change into absolutely path
if(tfsDir != "/"){
tfsDir += "/";
}
}
if (tfsFilename.empty()){
tfsFilename = localFilename;
}
tfsPath = tfsDir + tfsFilename;
cout << "put " << localPath << " " << tfsPath << endl;
try{
if( !fs.existDirectory(tfsDir) ){
cout << "Error: no such directory " << tfsDir << endl;
return false;
}
//if the file is exist , the local file will be appended
if( !fs.existFile(tfsPath) ){
int chunkSize = (fileStat.st_size > MAX_CHUNK_SIZE) ? MAX_CHUNK_SIZE:DEFAULT_CHUNK_SIZE;
chunkSize = chunkSize - chunkSize % blocksize;
fs.createFile(tfsPath, 2 , chunkSize);
}
AppendStream tfsAppend;
int bufferSize = (fileStat.st_size < MAX_BUFFER_SIZE) ? MAX_BUFFER_SIZE:DEFAULT_BUFFER_SIZE;
tfsAppend.open(tfsPath, bufferSize);
ifstream fin(localPath.c_str() , ios::binary);
if(!fin){
cout << "ERROR: put: open file " << localPath << endl;
return false;
}
size_t MAXGET = 1024 * 1024 / blocksize * blocksize;
if (MAXGET == 0) throw (TFSException("Block Size Exceed 1 M"));
char *buffer = new char[MAXGET];
while(fin){
fin.read(buffer, MAXGET);
//cout << "read " << fin.gcount() << endl;
tfsAppend.append(buffer, fin.gcount());
}
}
catch(TFSException& ex){
cout << "ERROR: put: Get exception: " << ex.what() << endl;
return false;
}
return true;
}