public String input() { if (id > 0) { model = docInfoManager.get(id); } return INPUT; }
public void download() throws Exception { DocInfo docInfo = docInfoManager.get(id); File file = new File("target/uploaded", docInfo.getPath()); InputStream is = null; try { is = new FileInputStream(file); IoUtils.copyStream(is, ServletActionContext.getResponse().getOutputStream()); } finally { if (is != null) { is.close(); } } }
public String save() throws Exception { DocInfo dest = null; if (id > 0) { dest = docInfoManager.get(id); beanMapper.copy(model, dest); } else { dest = model; String userId = userConnector .findByUsername( SpringSecurityUtils.getCurrentUsername(), ScopeHolder.getUserRepoRef()) .getId(); dest.setUserId(Long.parseLong(userId)); } new File("target/uploaded").mkdirs(); File targetFile = new File("target/uploaded", attachment.getName()); InputStream is = null; OutputStream os = null; try { is = new FileInputStream(attachment); os = new FileOutputStream(targetFile); IoUtils.copyStream(is, os); } finally { if (is != null) { is.close(); } if (os != null) { os.close(); } } dest.setPath(targetFile.getName()); docInfoManager.save(dest); addActionMessage(messages.getMessage("core.success.save", "保存成功")); return RELOAD; }