Java Code Examples for cn.hutool.core.util.ZipUtil#unzip()
The following examples show how to use
cn.hutool.core.util.ZipUtil#unzip() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ThemeController.java From stone with GNU General Public License v3.0 | 5 votes |
/** * 上传主题 * * @param file 文件 * * @return JsonResult */ @RequestMapping(value = "/upload", method = RequestMethod.POST) @ResponseBody public JsonResult uploadTheme(@RequestParam("file") MultipartFile file, HttpServletRequest request) { try { if (!file.isEmpty()) { //获取项目根路径 final File basePath = new File(ResourceUtils.getURL("classpath:").getPath()); final File themePath = new File(basePath.getAbsolutePath(), new StringBuffer("templates/themes/").append(file.getOriginalFilename()).toString()); file.transferTo(themePath); log.info("Upload topic success, path is " + themePath.getAbsolutePath()); logsService.save(LogsRecord.UPLOAD_THEME, file.getOriginalFilename(), request); ZipUtil.unzip(themePath, new File(basePath.getAbsolutePath(), "templates/themes/")); FileUtil.del(themePath); HaloConst.THEMES.clear(); HaloConst.THEMES = HaloUtils.getThemes(); } else { log.error("Upload theme failed, no file selected"); return new JsonResult(ResultCodeEnum.FAIL.getCode(), localeMessageUtil.getMessage("code.admin.theme.upload-no-file")); } } catch (Exception e) { log.error("Upload theme failed: {}", e.getMessage()); return new JsonResult(ResultCodeEnum.FAIL.getCode(), localeMessageUtil.getMessage("code.admin.theme.upload-failed")); } return new JsonResult(ResultCodeEnum.SUCCESS.getCode(), localeMessageUtil.getMessage("code.admin.theme.upload-success")); }
Example 2
Source File: ThemeController.java From blog-sharon with Apache License 2.0 | 5 votes |
/** * 上传主题 * * @param file 文件 * @return JsonResult */ @RequestMapping(value = "/upload", method = RequestMethod.POST) @ResponseBody public JsonResult uploadTheme(@RequestParam("file") MultipartFile file, HttpServletRequest request) { try { if (!file.isEmpty()) { //获取项目根路径 File basePath = new File(ResourceUtils.getURL("classpath:").getPath()); File themePath = new File(basePath.getAbsolutePath(), new StringBuffer("templates/themes/").append(file.getOriginalFilename()).toString()); file.transferTo(themePath); log.info("Upload topic success, path is " + themePath.getAbsolutePath()); logsService.save(LogsRecord.UPLOAD_THEME, file.getOriginalFilename(), request); ZipUtil.unzip(themePath, new File(basePath.getAbsolutePath(), "templates/themes/")); FileUtil.del(themePath); HaloConst.THEMES.clear(); HaloConst.THEMES = HaloUtils.getThemes(); } else { log.error("Upload theme failed, no file selected"); return new JsonResult(ResultCodeEnum.FAIL.getCode(), localeMessageUtil.getMessage("code.admin.theme.upload-no-file")); } } catch (Exception e) { log.error("Upload theme failed: {}", e.getMessage()); return new JsonResult(ResultCodeEnum.FAIL.getCode(), localeMessageUtil.getMessage("code.admin.theme.upload-failed")); } return new JsonResult(ResultCodeEnum.SUCCESS.getCode(), localeMessageUtil.getMessage("code.admin.theme.upload-success")); }
Example 3
Source File: TestFile.java From Jpom with MIT License | 4 votes |
public static void main(String[] args) throws IOException { InputStream inputStream = new FileInputStream("D:\\SystemDocument\\Desktop\\Desktop.zip"); String code = IoUtil.readHex28Upper(inputStream); System.out.println(code); System.out.println(FileUtil.getMimeType("D:\\SystemDocument\\Desktop\\Desktop.zip")); System.out.println(FileUtil.getMimeType("D:\\SystemDocument\\Desktop\\Desktop.tar.gz")); System.out.println(FileUtil.getMimeType("D:\\SystemDocument\\Desktop\\Desktop.7z")); ZipUtil.unzip(new File("D:\\SystemDocument\\Desktop\\Desktop.tar.gz"), new File("D:\\SystemDocument\\Desktop\\Desktop.7z\"")); ZipUtil.unzip(new File("D:\\SystemDocument\\Desktop\\Desktop.7z"), new File("D:\\SystemDocument\\Desktop\\Desktop.7z\"")); System.out.println(FileUtil.extName("test.zip")); }
Example 4
Source File: SshInstallAgentController.java From Jpom with MIT License | 4 votes |
@RequestMapping(value = "installAgentSubmit.json", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) @ResponseBody @Feature(method = MethodFeature.INSTALL) @OptLog(UserOperateLogV1.OptType.SshInstallAgent) public String installAgentSubmit(@ValidatorItem(value = ValidatorRule.NOT_BLANK) String id, @ValidatorItem(value = ValidatorRule.NOT_BLANK, msg = "节点数据") String nodeData, @ValidatorItem(value = ValidatorRule.NOT_BLANK, msg = "安装路径") String path) throws Exception { // 判断输入的节点信息 Object object = getNodeModel(nodeData); if (object instanceof JsonMessage) { return object.toString(); } NodeModel nodeModel = (NodeModel) object; // SshModel sshModel = sshService.getItem(id); Objects.requireNonNull(sshModel, "没有找到对应ssh"); // String tempFilePath = ServerConfigBean.getInstance().getUserTempPath().getAbsolutePath(); MultipartFileBuilder cert = createMultipart().addFieldName("file").setSavePath(tempFilePath); String filePath = cert.save(); // File outFle = FileUtil.file(tempFilePath, Type.Agent.name() + "_" + IdUtil.fastSimpleUUID()); try { try (ZipFile zipFile = new ZipFile(filePath)) { // 判断文件是否正确 ZipEntry sh = zipFile.getEntry(Type.Agent.name() + ".sh"); ZipEntry lib = zipFile.getEntry("lib" + StrUtil.SLASH); if (sh == null || null == lib || !lib.isDirectory()) { return JsonMessage.getString(405, "不能jpom 插件包"); } ZipUtil.unzip(zipFile, outFle); } // 获取上传的tag File shFile = FileUtil.file(outFle, Type.Agent.name() + ".sh"); List<String> lines = FileUtil.readLines(shFile, CharsetUtil.CHARSET_UTF_8); String tag = null; for (String line : lines) { line = line.trim(); if (StrUtil.startWith(line, "Tag=\"") && StrUtil.endWith(line, "\"")) { tag = line.substring(5, line.length() - 1); break; } } if (StrUtil.isEmpty(tag)) { return JsonMessage.getString(405, "管理命令中不存在tag"); } // 读取授权信息 File configFile = FileUtil.file(outFle, "extConfig.yml"); if (configFile.exists()) { List<Map<String, Object>> load = YmlUtil.load(configFile); Map<String, Object> map = load.get(0); Object user = map.get(ConfigBean.AUTHORIZE_USER_KEY); nodeModel.setLoginName(Convert.toStr(user, "")); // Object pwd = map.get(ConfigBean.AUTHORIZE_PWD_KEY); nodeModel.setLoginPwd(Convert.toStr(pwd, "")); } // 查询远程是否运行 if (sshService.checkSshRun(sshModel, tag)) { return JsonMessage.getString(300, "对应服务器中已经存在Jpom 插件端,不需要再次安装啦"); } // 上传文件到服务器 sshService.uploadDir(sshModel, path, outFle); // String shPtah = FileUtil.normalize(path + "/" + Type.Agent.name() + ".sh"); String command = StrUtil.format("sh {} start upgrade", shPtah); String result = sshService.exec(sshModel, command); // 休眠10秒 Thread.sleep(10 * 1000); if (StrUtil.isEmpty(nodeModel.getLoginName()) || StrUtil.isEmpty(nodeModel.getLoginPwd())) { String error = this.getAuthorize(sshModel, nodeModel, path); if (error != null) { return error; } } nodeModel.setOpenStatus(true); // 绑定关系 nodeModel.setSshId(sshModel.getId()); nodeService.addItem(nodeModel); // return JsonMessage.getString(200, "操作成功:" + result); } finally { // 清理资源 FileUtil.del(filePath); FileUtil.del(outFle); } }