当前位置: 首页 > news >正文

淘宝的好券网站怎么做优化大师官方免费下载

淘宝的好券网站怎么做,优化大师官方免费下载,网站建设模块怎么使用,教育网站建设公司背景&#xff1a;最近做一个腾讯 cos 桶 文件的读写与本地数据库查询等操作 Retrofit 中文件下载的可以添加 Streaming StreamingGETObservable<ResponseBody> downloadCosFile(Url String downloadUrl);Streaming 的作用&#xff1a; 注解通常用于指示Retrofit或其他HTT…

背景:最近做一个腾讯 cos 桶 文件的读写与本地数据库查询等操作
Retrofit 中文件下载的可以添加 @Streaming

    @Streaming@GETObservable<ResponseBody> downloadCosFile(@Url String downloadUrl);

@Streaming 的作用:
注解通常用于指示Retrofit或其他HTTP请求库将响应的内容作为流式数据而不是将其全部加载到内存中。这对于处理大文件或流式传输非常有用,因为它可以减少内存占用并提高性能。

HttpCenter.getInstance().requestResponse(HttpCenter.getInstance().getApi().downloadCosFile(fileDownloadPath), new HttpObserver<ResponseBody>(ApiService.GET_COS_FILE_INFO) {@Overrideprotected void onFailure(ApiException e) {NLog.i(TAG, "onFailure:  cos 文件 请求失败" + e.getMessage());callBack.onResult(null);}@Overrideprotected void onSuccess(ResponseBody responseBody) {NLog.i(TAG, "onSuccess:  cos 文件 请求成功");// 下载文件AppExecutors.autoExecute(() -> {// 读入请求体的输入流InputStream inputStream = responseBody.byteStream();// 指定文件全路径-》 引申获取Android 几种路径的方式String zipFilePath = "fileObsolutePath" File outputFile = new File(zipFilePath); // 保存到应用的私有目录try (FileOutputStream outputStream = new FileOutputStream(outputFile)) {byte[] buffer = new byte[4 * 1024];int read;while ((read = inputStream.read(buffer)) != -1) {outputStream.write(buffer, 0, read);}outputStream.flush();NLog.i(TAG, "onSuccess: 文件写入成功");String unZipFileDir;ZipUtils.UnZipFolder(outputFile.getAbsolutePath(), unZipFileDir, unZipPathList -> {if (unZipPathList != null && unZipPathList.size() > 0) {// 每个压缩文件下只有一个文件,所以直接取第一个解压文件路径NLog.i(TAG, "onSuccess: 解压成功 " + unZipPathList.get(0));callBack.onResult(unZipPathList.get(0));} else {callBack.onResult(null);}});// 删除所有解析数据deleteDirectory(FileUtil.getSecondFolder(DOWNLOAD_COS_DIR));} catch (FileNotFoundException e) {e.printStackTrace();} catch (IOException e) {e.printStackTrace();}});}
}

ZipUtils.java 解压文件

public static void UnZipFolder(String zipFileString, String outPathString, ICommListener<List<String>> iCommListener) throws IOException {ZipInputStream inZip = new ZipInputStream(new FileInputStream(zipFileString));ZipEntry zipEntry;String szName = "";List<String> unZipPathList = new ArrayList<>();while ((zipEntry = inZip.getNextEntry()) != null) {szName = zipEntry.getName();NLog.i(TAG, "UnZipFolder: zipEntry " + szName);if (zipEntry.isDirectory()) {NLog.i(TAG, "UnZipFolder: 解压目录 ");//获取部件的文件夹名szName = szName.substring(0, szName.length() - 1);File folder = new File(outPathString + File.separator + szName);folder.mkdirs();} else {NLog.i(TAG, "UnZipFolder: 解压文件 ");String unZipPath = outPathString + File.separator + szName;File file = new File(unZipPath);if (!file.exists()) {file.getParentFile().mkdirs();file.createNewFile();}// 获取文件的输出流FileOutputStream out = new FileOutputStream(file);int len;byte[] buffer = new byte[1024];// 读取(字节)字节到缓冲区while ((len = inZip.read(buffer)) != -1) {// 从缓冲区(0)位置写入(字节)字节out.write(buffer, 0, len);out.flush();}out.close();unZipPathList.add(unZipPath);NLog.i(TAG, "UnZipFolder: 解压文件写入完成 ");}}inZip.close();iCommListener.onResult(unZipPathList);NLog.i(TAG, "UnZipFolder: 解压结束");}

删除目录

 public static boolean deleteDir(final File dir) {if (dir == null) return false;// dir doesn't exist then return trueif (!dir.exists()) return true;// dir isn't a directory then return falseFile[] files = dir.listFiles();if (files != null && files.length != 0) {for (File file : files) {if (file.isFile()) {if (!file.delete()) return false;} else if (file.isDirectory()) {if (!deleteDir(file)) return false;}}}return dir.delete();}
http://www.hrbkazy.com/news/49821.html

相关文章:

  • 网站做点击收费标准长春百度seo公司
  • 百度官方营销推广平台有哪些seo快速排名软件网址
  • 个人电脑做服务器网站色盲测试图免费测试
  • 辽宁购物网站制作百度下载安装免费
  • wordpress如何显示首页seo百度刷排名
  • 呼和浩特网站建设怎么投放网络广告
  • 钉钉小程序开发平台seo优化要做什么
  • 外包建设网站潍坊网站建设公司
  • 海外推广广告知了seo
  • 外贸日文网站网站seo视频
  • 手机微信网站怎么做的好处培训心得体会范文大全1000
  • 成都广告设计公司电话seo网站推广软件排名
  • 网站群建设讲话手机百度下载
  • 找别人做网站注意事项搜索引擎营销的主要方法包括
  • 网站定制开发怎么写seozhun
  • 网站seo快速百度招聘2022年最新招聘
  • 个人备案网站可以做论坛吗十大互联网广告公司
  • 引导型网站设计关键词推广效果
  • phpweb网站开发参考文献自动外链
  • 网站前端是什么关键词排名优化工具
  • 廊坊安次区网站建设公司2023年国家免费技能培训
  • 网站及网页设计费用google官网入口
  • 开网店的基础知识西安seo引擎搜索优化
  • 西宁做网站的网络公司附近电脑培训速成班一个月
  • 网站建设公司 电话销售没什么效果网络软文投放
  • wordpress返回首页一直加载网站百度seo关键词优化
  • 汉中网站建设报价南宁seo服务优化
  • 建德网站设计公司网络推广的网站有哪些
  • 四川网站营销seo什么价格互联网营销师国家职业技能标准
  • go语言网站开发磁力兔子