博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Java的新项目学成在线笔记-day13(十三)
阅读量:7220 次
发布时间:2019-06-29

本文共 2348 字,大约阅读时间需要 7 分钟。

6.3.5.3 分块检查

在Service 中定义分块检查方法:

[mw_shl_code=applescript,true]//得到块文件所在目录 private String getChunkFileFolderPath(String fileMd5){ String fileChunkFolderPath = getFileFolderPath(fileMd5) +"/" + "chunks" + "/";      return fileChunkFolderPath;      } //检查块文件 public CheckChunkResult checkchunk(String fileMd5, String chunk, String chunkSize) {    //得到块文件所在路径     String chunkfileFolderPath = getChunkFileFolderPath(fileMd5);     //块文件的文件名称以1,2,3..序号命名,没有扩展名     File chunkFile = new File(chunkfileFolderPath+chunk);     if(chunkFile.exists()){         return new CheckChunkResult(MediaCode.CHUNK_FILE_EXIST_CHECK,true);     }else{         return new CheckChunkResult(MediaCode.CHUNK_FILE_EXIST_CHECK,false);     } }[/mw_shl_code]6.3.5.4 上传分块 在Service 中定义分块上传分块方法:[mw_shl_code=applescript,true]//块文件上传 public ResponseResult uploadchunk(MultipartFile file, String fileMd5, String chunk) {     if(file == null){         ExceptionCast.cast(MediaCode.UPLOAD_FILE_REGISTER_ISNULL);     }     //创建块文件目录     boolean fileFold = createChunkFileFolder(fileMd5);     //块文件     File chunkfile = new File(getChunkFileFolderPath(fileMd5) + chunk);     //上传的块文件     InputStream inputStream= null;     FileOutputStream outputStream = null;     try {         inputStream = file.getInputStream();         outputStream = new FileOutputStream(chunkfile);         IOUtils.copy(inputStream,outputStream);     } catch (Exception e) {         e.printStackTrace();         LOGGER.error("upload chunk file fail:{}",e.getMessage());         ExceptionCast.cast(MediaCode.CHUNK_FILE_UPLOAD_FAIL);     }finally {         try {             inputStream.close();         } catch (IOException e) {             e.printStackTrace();         }         try {             outputStream.close();         } catch (IOException e) {             e.printStackTrace();        }       }     return new ResponseResult(CommonCode.SUCCESS); }    //创建块文件目录    private boolean createChunkFileFolder(String fileMd5){         //创建上传文件目录         String chunkFileFolderPath = getChunkFileFolderPath(fileMd5);         File chunkFileFolder = new File(chunkFileFolderPath);         if (!chunkFileFolder.exists()) {             //创建文件夹             boolean mkdirs = chunkFileFolder.mkdirs();             return mkdirs;         }         return true;     }[/mw_shl_code]

转载于:https://blog.51cto.com/13517854/2409031

你可能感兴趣的文章
李洪强iOS经典面试题37-解释垃圾回收的原理
查看>>
多校第二场 1004 hdu 5303 Delicious Apples(背包+贪心)
查看>>
Executor , ExecutorService 和 Executors
查看>>
关于图数据库查询语言:Cypher
查看>>
Android中m、mm、mmm、mma、mmma的区别
查看>>
知道各个层使用的是哪个数据交换设备
查看>>
MySQL索引类型总结和使用技巧以及注意事项
查看>>
iOS:在cell中使用倒计时的最佳方法
查看>>
深入浅出空间索引:为什么需要空间索引
查看>>
EF 数据版本号,处理具体使用方法 RowVersion / Timestamp 使用方法。进行自动处理并发修改...
查看>>
centos6.5关闭ipv6
查看>>
springboot整合mybatis将sql打印到日志
查看>>
自定义视图
查看>>
dedecms后台管理员密码重置方法
查看>>
JS函数节流和函数防抖问题分析
查看>>
116 - Unidirectional TSP(DP)
查看>>
内存泄露问题
查看>>
Python type()函数用途及使用方法
查看>>
Autohotkey window 下宏键盘、宏命令开发入门
查看>>
验证码处理类:UnCodebase.cs + BauDuAi 读取验证码的值(并非好的解决方案)
查看>>