SamiBoolQuery::SamiBoolQuery(String* json) { init(); String str(json->GetPointer()); int length = str.GetLength(); ByteBuffer buffer; buffer.Construct(length); for (int i = 0; i < length; ++i) { byte b = str[i]; buffer.SetByte(b); } IJsonValue* pJson = JsonParser::ParseN(buffer); fromJsonObject(pJson); if (pJson->GetType() == JSON_TYPE_OBJECT) { JsonObject* pObject = static_cast< JsonObject* >(pJson); pObject->RemoveAll(true); } else if (pJson->GetType() == JSON_TYPE_ARRAY) { JsonArray* pArray = static_cast< JsonArray* >(pJson); pArray->RemoveAll(true); } delete pJson; }
SamiShowcaseDatatypePrimitives* SamiShowcaseDatatypePrimitives::fromJson(String* json) { this->cleanup(); String str(json->GetPointer()); int length = str.GetLength(); ByteBuffer buffer; buffer.Construct(length); for (int i = 0; i < length; ++i) { byte b = str[i]; buffer.SetByte(b); } IJsonValue* pJson = JsonParser::ParseN(buffer); fromJsonObject(pJson); if (pJson->GetType() == JSON_TYPE_OBJECT) { JsonObject* pObject = static_cast< JsonObject* >(pJson); pObject->RemoveAll(true); } else if (pJson->GetType() == JSON_TYPE_ARRAY) { JsonArray* pArray = static_cast< JsonArray* >(pJson); pArray->RemoveAll(true); } delete pJson; return this; }
PacketHeader* PacketHeader::parse(byte* rawData) { PacketHeader *header=new PacketHeader(); ByteBuffer byteBuffer; byteBuffer.Construct(rawData, 0, LENGTH, LENGTH); byteBuffer.GetArray(PacketHeader::opCodeBuffer, 0, OPCODE_LENGTH); //for(int i=0; i<2; i++) { // AppLog("Array(2) : %d", PacketHeader::opCodeBuffer[i]); //} header->setOpCode(ByteToInt(PacketHeader::opCodeBuffer, OPCODE_LENGTH)); //AppLog("OPCODE : %d", header->getOpCode()); byteBuffer.GetArray(PacketHeader::packetSizeBuffer, 0, PAYLOAD_LENGTH); //for(int i=0; i<4; i++) { // AppLog("Array(4) : %d", PacketHeader::packetSizeBuffer[i]); //} header->setPayloadLength( ByteToInt(PacketHeader::packetSizeBuffer, PAYLOAD_LENGTH) //4 - PacketHeader::LENGTH); //AppLog("OPCODE : %d", header->getPayloadLength()); return header; }
bool SimpleCache::GetFileForIndex(int index, ByteBuffer & data) { String filePath; BuildPathForFileInCache(index, filePath); if (!File::IsFileExist(filePath)) { return false; } AppLog("Reading data from cached file at %S", filePath.GetPointer()); File cachedFile; cachedFile.Construct(filePath, L"r+"); if (IsFailed(GetLastResult())) { AppLog("Error opening destination file in cache"); return false; } FileAttributes fAttributes; File::GetAttributes(filePath, fAttributes); data.Construct(fAttributes.GetFileSize()); cachedFile.Read(data); AppLog("Read cache: %d bytes", data.GetCapacity()); if (IsFailed(GetLastResult())) { AppLog("Error reading from cached file"); return false; } return true; }
result Enrollment::ReceiveDataUDP(void) { result res = E_SUCCESS; ByteBuffer txBuffer; unsigned long buflen = 0; __pSocket->Ioctl(NET_SOCKET_FIONREAD, buflen); txBuffer.Construct(buflen + 1); Ip4Address peerAddr1(NET_SOCKET_INADDR_ANY); unsigned short port = 0; NetEndPoint point(peerAddr1, port); res = __pSocket->ReceiveFrom(txBuffer, point); if (__pUdpEndpoint == null) { __pUdpEndpoint = new (std::nothrow) NetEndPoint(point); } else { if (__pUdpEndpoint->GetNetEndPoint() != point.GetNetEndPoint()) { AppLog("It's a data from other endpoint so discard"); return res; } } TryReturn(res == E_SUCCESS, res, "Receive Failed %d", res); res = DisplayText(txBuffer, buflen); txBuffer.Clear(); return res; }
result Enrollment::SendData() { String data = ""; ByteBuffer* pTxBuffer = null; ByteBuffer buffer; result res = E_SUCCESS; for (int i = 0; i < 4; i++) { data.Append(__pWorkList[i]->GetText()); data.Append("\n"); } if (data.IsEmpty()) { AppLog("There is no data to send"); return E_SUCCESS; } pTxBuffer = Tizen::Base::Utility::StringUtil::StringToUtf8N(data); TryReturn(pTxBuffer != null, E_OUT_OF_MEMORY, "Failed to allocate ByteBuffer"); AppLog("Text Length %d", pTxBuffer->GetLimit()); buffer.Construct(pTxBuffer->GetLimit()); buffer.CopyFrom(*pTxBuffer); buffer.Flip(); delete pTxBuffer; res = __pSocket->SendTo(buffer, *__pUdpEndpoint); if (res != E_SUCCESS && res != E_WOULD_BLOCK) AppLog("Error sending data"); buffer.Clear(); return res; }
int trueStringLength(const char *str, int len){ Tizen::Base:: String bada_str; ByteBuffer buffer; buffer.Construct(len + 1); buffer.SetArray(( byte*)str, 0, len); buffer.SetByte( '\0'); buffer.Flip(); Tizen::Text::Utf8Encoding utf8; int charCount; utf8.GetCharCount(buffer, charCount); return charCount; }
void ZLbadaPaintContext::drawString(int x, int y, const char *str, int len, bool rtl){ Tizen::Base::String bada_str; ByteBuffer buffer; buffer.Construct(len + 1); buffer.SetArray((byte*)str, 0, len); buffer.SetByte('\0'); buffer.Flip(); //AppLog("ZLbadaPaintContext::drawString %s",(const char *)str); // StringUtil::Utf8ToString((const char *)buffer.GetPointer(), bada_str); Utf8Encoding utf8; int charCount; utf8.GetCharCount(buffer, charCount); utf8.GetString(buffer, bada_str); // AppLog("charCount = %d : len = %d", charCount,len); // DrawEnrichedTex(x, y-myFont->GetMaxHeight(),bada_str ); // AppLog("myStoredSize = %d ", myStoredSize); // AppLog("myFont->GetMaxHeight() = %d ", myFont->GetMaxHeight()); //Tizen::Graphics::Color clr = Tizen::Graphics::Color::COLOR_GREEN; if ((myFont!=0)&&(pCanvas!=0)) { // AppLog("pCanvas->SetFont(*myFont)"); // pCanvas->SetFont(*myFont); if (myStoredItalic) pCanvas->DrawText(Point(x, y - myFont->GetMaxHeight()+ deltaItalic), bada_str); else pCanvas->DrawText(Point(x, y - myFont->GetMaxHeight()), bada_str); } // AppLog("ZLbadaPaintContext::drawString end"); /* if (!myStoredItalic) pCanvas->DrawText(Point(x, y-myFont->GetMaxHeight()), bada_str); else{ int startX = x; int startY= y-myFont->GetMaxHeight(); mchar ch; for (int i=0; i<charCount; i++){ bada_str.GetCharAt(i, ch); int rb; myFont->GetRightBear(ch, rb); int lb; myFont->GetLeftBear(ch, lb); pCanvas->DrawText(Point(startX, startY), ch); startX = startX + rb; } } */ //pCanvas->DrawText(Point(x, y-myFont->GetMaxHeight()), bada_str, Tizen::Graphics::Color::COLOR_WHITE); // pCanvas->DrawText(Point(x, y-myFont->GetMaxHeight()), bada_str, charCount); // pCanvas->DrawText(Point(x, y), bada_str,charCount); }
void FBReader::openLinkInBrowser(const std::string &url) const { if (url.empty()) { return; } AppLog("openLinkInBrowser url=%s",url.c_str()); int len = url.length(); String bada_str; ByteBuffer buffer; buffer.Construct(len + 1); buffer.SetArray((const byte*)url.data(), 0, len); buffer.SetByte( '\0'); buffer.Flip(); Utf8Encoding utf8; int charCount; utf8.GetCharCount(buffer, charCount); utf8.GetString(buffer, bada_str); ArrayList* pDataList = null; pDataList = new ArrayList(); pDataList->Construct(); String* pData = null; pData = new String(L"url:" + bada_str); //pData = new String(L"url:http://www.bada.com"); pDataList->Add(*pData); //APPCONTROL_BROWSER //TODO Tizen AppControl* pAc;// rem TIZEN !!!!!!!!!= AppManager::FindAppControlN(APPCONTROL_BROWSER, OPERATION_VIEW); //AppControl* pAc = AppManager::FindAppControlN(APPCONTROL_PROVIDER_BROWSER, APPCONTROL_OPERATION_VIEW); if (pAc) { pAc->Start(pDataList, null); delete pAc; } pDataList->RemoveAll(true); delete pDataList; /* shared_ptr<ProgramCollection> collection = webBrowserCollection(); if (collection.isNull()) { return; } shared_ptr<Program> program = collection->currentProgram(); if (program.isNull()) { return; } std::string copy = url; // NetworkLinkCollection::Instance().rewriteUrl(copy, true); ZLLogger::Instance().println("URL", copy); program->run("openLink", copy);*/ }
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; }
result Enrollment::ReceiveDataTCP(void) { result res = E_SUCCESS; ByteBuffer txBuffer; String data; unsigned long buflen = 0; // Get the size of data received __pSocket->Ioctl(NET_SOCKET_FIONREAD, buflen); txBuffer.Construct(buflen + 1); res = __pSocket->Receive(txBuffer); TryReturn(res == E_SUCCESS, res, "Receive Failed"); res = DisplayText(txBuffer, buflen); txBuffer.Clear(); return res; }
void AttachPhotoElement::OnUploadSuccess(Tizen::Web::Json::JsonObject *savedPhoto) { ByteBuffer buffer; buffer.Construct(100000); JsonArray *array; JsonParseUtils::GetArray(savedPhoto, L"response", array); JsonObject *response; JsonParseUtils::GetObject(array, 0, response); JsonParseUtils::GetObject(savedPhoto, L"response", response); JsonParseUtils::GetInteger(*response, L"owner_id", _ownerId); JsonParseUtils::GetInteger(*response, L"id", _id); _loading = false; SetUploaded(true); RequestRedraw(true); RemoveControl(_pProgress); }
int ZLbadaPaintContext::stringWidth(const char *str, int len, bool) const { Tizen::Base::String bada_str; ByteBuffer buffer; buffer.Construct(len + 1); buffer.SetArray((byte*)str, 0, len); buffer.SetByte('\0'); buffer.Flip(); // AppLog("ZLbadaPaintContext::stringWidth %s",(const char *)buffer.GetPointer()); // StringUtil::Utf8ToString((const char *)buffer.GetPointer(), bada_str); Utf8Encoding utf8; int charCount; utf8.GetCharCount(buffer, charCount); utf8.GetString(buffer, bada_str); Dimension dim; //if (!myStoredItalic) { myFont->GetTextExtent(bada_str, charCount, dim); // AppLog("dim.width %d",dim.width); return dim.width;// + charCount*(myFont->GetCharSpace()); /*} else{ int width = 0; //int startY = y-myFont->GetMaxHeight(); mchar ch; for (int i=0; i<charCount; i++){ bada_str.GetCharAt(i, ch); int rb; myFont->GetRightBear(ch, rb); // int lb; // myFont->GetLeftBear(ch, lb); // pCanvas->DrawText(Point(startX, startY), ch); AppLog("width %d",width); width = width + rb; } return width; }*/ }
result Enrollment::SendDataCommand(String command) { ByteBuffer* pTxBuffer = null; ByteBuffer buffer; result res = E_SUCCESS; TryReturn(__isTcp == false, E_SYSTEM, "Sending Command not required for TCP connection"); pTxBuffer = Tizen::Base::Utility::StringUtil::StringToUtf8N(command); TryReturn(pTxBuffer != null, E_OUT_OF_MEMORY, "Failed to allocate ByteBuffer"); buffer.Construct(1024); buffer.CopyFrom(*pTxBuffer); delete pTxBuffer; buffer.Flip(); do { if (__pUdpEndpoint != null) { res = __pSocket->SendTo(buffer, *__pUdpEndpoint); } if (res == E_WOULD_BLOCK) { AppLog("Would block for data sending will try to retransmit"); Tizen::Base::Runtime::Thread::Sleep(500); } else if (res != E_SUCCESS) { AppLog("Error sending data"); break; } else { AppLog("Command successfully sent"); break; } } while (1); AppLog("Loop completed"); buffer.Clear(); return res; }
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; }
HttpThread::HttpThread(std::string const & url, downloader::IHttpThreadCallback & callback, int64_t beg, int64_t end, int64_t size, string const & pb) : m_callback(callback), m_begRange(beg), m_endRange(end), m_downloadedBytes(0), m_expectedSize(size), m_url(url), m_pb(pb), m_pSession(0), m_pTransaction(0) { result r = E_SUCCESS; String * pProxyAddr = 0; String hostAddr(m_url.c_str()); HttpHeader * header = 0; LOG(LDEBUG, ("Creating HttpSession", m_url)); m_pSession = new HttpSession(); r = m_pSession->Construct(NET_HTTP_SESSION_MODE_NORMAL, pProxyAddr, hostAddr, header); if (r != E_SUCCESS) { LOG(LERROR, ("HttpSession Construction error:", r)); return; } // Open a new HttpTransaction. m_pTransaction = m_pSession->OpenTransactionN(); if ((r = GetLastResult()) != E_SUCCESS) { LOG(LERROR, ("OpenTransactionN", GetLastResult())); return; } m_pTransaction->AddHttpTransactionListener(*this); m_pTransaction->SetHttpProgressListener(*this); HttpRequest * pRequest = m_pTransaction->GetRequest(); pRequest->SetUri(m_url.c_str()); HttpHeader * pHeader = pRequest->GetHeader(); // use Range header only if we don't download whole file from start if (!(m_begRange == 0 && m_endRange < 0)) { if (m_endRange > 0) { LOG(LDEBUG, (m_url, "downloading range [", m_begRange, ",", m_endRange, "]")); String range("bytes="); range.Append(m_begRange); range.Append('-'); range.Append(m_endRange); pHeader->AddField(L"Range", range); } else { LOG(LDEBUG, (m_url, "resuming download from position", m_begRange)); String range("bytes="); range.Append(m_begRange); range.Append('-'); pHeader->AddField("Range", range); } } // set user-agent with unique client id only for mapswithme requests if (m_url.find("mapswithme.com") != string::npos) { static string const uid = GetPlatform().UniqueClientId(); pHeader->AddField("User-Agent", uid.c_str()); } if (m_pb.empty()) { pRequest->SetMethod(NET_HTTP_METHOD_GET); } else { pRequest->SetMethod(NET_HTTP_METHOD_POST); pHeader->AddField("Content-Type", "application/json"); int64_t const sz = m_pb.size(); String length; length.Append(sz); pHeader->AddField("Content-Length", length); ByteBuffer body; body.Construct((const byte *)m_pb.c_str(), 0, sz, sz); pRequest->WriteBody(body); } LOG(LDEBUG, ("Connecting to", m_url, "[", m_begRange, ",", m_endRange, "]", "size=", m_expectedSize)); m_pTransaction->Submit(); }