📄 fileiomanageri.cpp
字号:
#include "FileIOManagerI.h"
Ice::ObjectAdapterPtr FileIOManagerI::_adapter;
FileIOManagerI::FileIOManagerI(const Ice::CommunicatorPtr & ic){
_adapter->add(this, ic->stringToIdentity("FileIOManager"));
}
bool FileIOManagerI::writeFile(const ::std::string& blockIndex,const ::ClientClerk::BinaryData& data, const ::Ice::Current&){
string fileName = "data/" + blockIndex + ".data";
cout<<"writeFile :"<<fileName.c_str()<<endl;
ofstream out(fileName.c_str(),ios::out|ios::binary);
int bufferSize = data.size();
unsigned char* buffer = new unsigned char[bufferSize];
unsigned char* p = buffer;
for(int i=0;i<bufferSize;i++){
*p = data[i];
p++;
}
out.write((char*)buffer,bufferSize);
out.close();
delete []buffer;
this->m_paths[blockIndex] = fileName;
return true;
}
bool FileIOManagerI::readFile(const ::std::string& blockIndex,::ClientClerk::BinaryData& data, const ::Ice::Current&){
string fileName = this->m_paths[blockIndex];
cout<<"readFile :"<<fileName.c_str()<<endl;
if((_access(fileName.c_str(), 0)) == -1 ){
return false;
}
ifstream in(fileName.c_str(),ios::in|ios::binary);
in.seekg(0,ios::end);
int fileSize = in.tellg();
in.seekg(0,ios::beg);
unsigned char* buffer = new unsigned char[fileSize];
in.read((char*)buffer,fileSize);
in.close();
::ClientClerk::BinaryData temp(buffer,buffer+fileSize);
data.assign(temp.begin(),temp.end());
delete []buffer;
return true;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -