void withAssetData(const char* filename, const std::function<void(off64_t, const void*)>& callback) { auto asset = AAssetManager_open(g_assetManager, filename, AASSET_MODE_BUFFER); if (!asset) { throw std::runtime_error("Failed to open file"); } auto buffer = AAsset_getBuffer(asset); off64_t size = AAsset_getLength64(asset); callback(size, buffer); AAsset_close(asset); }
std::string ReadAssetFile::ReadFileToMemory(std::string &path) { AAsset *asset = AAssetManager_open(AndroidIOSystem::getAssetManager(), path.c_str(), AASSET_MODE_UNKNOWN); if (asset == NULL) Logger::printError("Failed open file from assets: " + path); std::size_t size = AAsset_getLength64(asset); std::string data; data.resize(size); AAsset_read(asset, &data[0], size); AAsset_close(asset); return data; }
size_t _size(const std::string &ipath) { auto mngr = spjni::getAssetManager(); if (!mngr) { return 0; } auto path = _getAssetsPath(ipath); AAsset* aa = AAssetManager_open(mngr, path.c_str(), AASSET_MODE_UNKNOWN); if (aa) { auto len = AAsset_getLength64(aa); AAsset_close(aa); return len; } return 0; }
stappler::filesystem::ifile _openForReading(const String &ipath) { auto mngr = spjni::getAssetManager(); if (!mngr) { return stappler::filesystem::ifile(); } auto path = _getAssetsPath(ipath); AAsset* aa = AAssetManager_open(mngr, path.c_str(), AASSET_MODE_UNKNOWN); if (aa) { auto len = AAsset_getLength64(aa); return stappler::filesystem::ifile((void *)aa, len); } return stappler::filesystem::ifile(); }