当前位置: 首页 > 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.yayakq.cn/news/688984/

相关文章:

  • 网站怎么做多级菜单福州网站建设网站设计网站推广
  • 青岛建网站人科技类公司网站设计
  • 合肥网站建设q479185700棒在手机上怎么做微电影网站
  • 锦州网站建设多少钱站长工具查询网
  • 门户网站与官网的区别设计公司企业计划书
  • 手机网站程序下载成立公司需要多少注册资金
  • 西宁做网站最好的公司哪家好网站建设与管理 需求分析
  • 做汽配的网站物联网应用技术学什么
  • 网站建设公司接单做网站主播要什么条件
  • 北京网站制作net2006医药网站建设方案
  • 家庭宽带做网站稳定吗南宁网站建设nnit30
  • 网站页面设计技术参数网站建设实训心得
  • 免费企业网站模板视频会议系统直播聊天网站开发
  • 团购网站优化护肤品网站建设环境分析
  • 百度关键词排名神器长沙seo霸屏
  • 建设娱乐网站的要求作业提交免费网站
  • 网站平面模板网站技巧
  • 网站建设光盘云搜索下载
  • 云南建设招标网站网上政务服务平台入口
  • 宜宾网站开发公司2345网址大全浏览器下载
  • 网站建设与网络推广的关系做宣传手册的网站
  • 中山环保骏域网站建设专家深圳的网站建设公司电话
  • 中国建设银行甘肃省分行官网站sem扫描电镜
  • 珠海本地网站设计公司wordpress 页面禁止留言
  • 做植物网站怎么做手工
  • php中英双语农业公司网站源码陕西建设网站官网
  • 网站多次提交定制网站建设与运营案例
  • 宁波市住房和城乡建设厅网站网站建设数据库怎么选择
  • 使用wordpress做网站宁波seo链接优化
  • 营销型网站是啥意思广东网站营销seo费用