文件恢复功能在Spring中不起作用。

时间:2018-12-03 07:53:37

标签: java spring-mvc

我对韩国的egovframework有问题。下载文件时,恢复功能不起作用。为了进行比较,我转到了Oracle主页并比较了下载,但是在Oracle中启用了暂停恢复功能,但是在我的文件中禁用了暂停按钮。 我已经编写了以下代码,这是什么问题?

@RequestMapping(value = "/cmm/fms/FileDown.do") public void cvplFileDownload(@RequestParam Map commandMap, HttpServletRequest request, HttpServletResponse response) throws Exception {

String atchFileId = (String) commandMap.get("atchFileId"); String fileSn = (String) commandMap.get("fileSn"); //egovframework login security Boolean isAuthenticated = EgovUserDetailsHelper.isAuthenticated(); if (isAuthenticated) { FileVO fileVO = new FileVO(); fileVO.setAtchFileId(atchFileId); fileVO.setFileSn(fileSn); FileVO fvo = fileService.selectFileInf(fileVO); File uFile = new File(fvo.getFileStreCours(), fvo.getStreFileNm()); long fSize = uFile.length(); long start = 0; if (fSize > 0) { String mimetype = "application/x-msdownload"; response.setHeader("Accept-Ranges", "bytes"); if(request.getHeader("Range") != null){ response.setStatus(HttpServletResponse.SC_PARTIAL_CONTENT); start = Long.parseLong(request.getHeader("Range").replaceAll("bytes=","").replaceAll("-", "")); } response.setHeader("Content-Length", new Long(fSize - start).toString()); if(start != 0 ){ response.setHeader("Content-Range", "bytes" + new Long(start).toString()+"-" + new Long(fSize - 1).toString()+"/" + new Long(fSize).toString()); } response.setContentType(mimetype); setDisposition(fvo.getOrignlFileNm(), request, response); BufferedInputStream in = null; BufferedOutputStream out = null; try { in = new BufferedInputStream(new FileInputStream(uFile)); in.skip(start); byte[] b = new byte[1024]; int i; while((i = in.read(b)) != -1){ response.getOutputStream().write(b,0,i); response.flushBuffer(); } in.close(); //FileCopyUtils.copy(in, out); //out.flush(); } catch (Exception ex) { LOGGER.debug("IGNORED: {}", ex.getMessage()); } finally { if (in != null) { try { in.close(); } catch (Exception ignore) { LOGGER.debug("IGNORED: {}", ignore.getMessage()); } } if (out != null) { try { out.close(); } catch (Exception ignore) { LOGGER.debug("IGNORED: {}", ignore.getMessage()); } } } } else { response.setContentType("application/octet-stream"); setDisposition(fvo.getOrignlFileNm()+"_오류", request, response); PrintWriter printwriter = response.getWriter(); printwriter.println(fvo.getOrignlFileNm()+" 파일이 존재하지 않습니다."); printwriter.flush(); printwriter.close(); } } }<code>

0 个答案:

没有答案