ArrayListT<Trip *> * IRailAPI::testRoutePlanner(){ result r = E_SUCCESS; String fileName(L"/Home/2.xml"); File *file = new File(); FileAttributes sourcefilemeta; File::GetAttributes(fileName, sourcefilemeta); int filesize = sourcefilemeta.GetFileSize(); ByteBuffer buffer; buffer.Construct(filesize); //AppLog("Read buffer size %d", buffer.GetLimit()); r = file->Construct(fileName, L"r"); //for write: w or w+ r = file->Read(buffer); //to write: file->Write *beware of the permission w instead of r delete file; //closes the file, there is no default close method for files, its gets closed when its scope is closed buffer.SetPosition(0); ArrayListT<Trip *> * test = createTripList(&buffer); //AppLog("completed trips"); return test; }
void RouteRequestManager::OnTransactionReadyToRead(Osp::Net::Http::HttpSession& httpSession, Osp::Net::Http::HttpTransaction& httpTransaction, int availableBodyLen){ AppLogDebug("http ready called"); HttpResponse* resp = httpTransaction.GetResponse(); //String status = resp->GetStatusText(); //AppLog("status: %S",status); ByteBuffer* buffer = (resp->ReadBodyN()); char data[buffer->GetLimit()+1]; buffer->SetPosition(0); buffer->GetArray((byte*)data, 0, buffer->GetLimit()); data[buffer->GetLimit()] ='\0'; String test(data); AppLogDebug("%S",test.GetPointer()); AppLogDebug("\n\n"); ArrayListT<Trip*>* trips=null; IRailAPI h; if(AppData::GetInstance()->getCurrentRequest() != null){ trips = h.createTripList(buffer); } if(trips != null){ if(!addToResults) AppData::GetInstance()->getCurrentRequest()->clearTrips(); AppData::GetInstance()->getCurrentRequest()->getTrips()->AddItems(*trips); //AppLog("parsing succesfull"); Controller::GetInstance()->switchToRoutePlannerResults(); } else{ //AppLogDebug("parsing failed"); Controller::GetInstance()->showServerErrorMessage(); } //write to file /* File f; int fileIndex = getRoutePlannerRegistryIndex(); f.Construct(L"/Home/history/RP"+ Integer::ToString(fileIndex) + ".xml",L"w+",false); f.Write(*buffer); */ }
result CategoryItemForm::ReadCustomListItems() { result r = E_SUCCESS; String dirName(L"/Home/catalog/"+dir); Directory* pDir; DirEnumerator* pDirEnum; pDir = new Directory; // allocate Directory instance // Open directory r = pDir->Construct(dirName); // Read all directory entries pDirEnum = pDir->ReadN(); String contentType; int i = 0; while(pDirEnum->MoveNext() == E_SUCCESS) { DirEntry dirEntry = pDirEnum->GetCurrentDirEntry(); if(dirEntry.IsNomalFile()) { //AppLog("%S", dirEntry.GetName().GetPointer()); if(!dirEntry.GetName().Equals("category.info", false)) { String fileName(dirName+"/"+dirEntry.GetName()); String title, desc; String iTempStr, iTempStr2; File file; result r = file.Construct(fileName, L"r"); if( IsFailed(r) ) { AppLog("File::Consturct() is failed by %s", GetErrorMessage(r)); } FileAttributes fileAttrs; file.GetAttributes(fileName, fileAttrs); long long size = fileAttrs.GetFileSize(); ByteBuffer readBuffer; readBuffer.Construct((int)size + 1); r = file.Read(readBuffer); if( IsFailed(r) ) { AppLog("File::Read() is failed by %s", GetErrorMessage(r)); } char* data = new char[readBuffer.GetLimit()+1]; readBuffer.SetPosition(0); readBuffer.GetArray((byte*)data, 0, readBuffer.GetLimit()); data[readBuffer.GetLimit()] ='\0'; //String str = String(data); String str; r = StringUtil::Utf8ToString(data, str); delete data; if(IsFailed(r)) { AppLog("File read error. File : %S", fileName.GetPointer()); continue; } file.Seek(FILESEEKPOSITION_BEGIN, 0); file.Read(title); r = TextPic::GetTranslated(title); if (IsFailed(r)) { continue; } int linecount = 0; while(file.Read(iTempStr) != E_END_OF_FILE) { linecount++; iTempStr2.Append(iTempStr); } anciilist.Add(*(new String(iTempStr2))); titlelist.Add(*(new String(title))); filelist.Add(*(new String(fileName))); ItemListForm::AddListItem(*CategoryList, title, iTempStr2, i++, linecount); file.Flush(); } } } delete pDirEnum; delete pDir; return r; }