Java Code Examples for cn.hutool.core.util.StrUtil#isEmpty()
The following examples show how to use
cn.hutool.core.util.StrUtil#isEmpty() .
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: CertModel.java From Jpom with MIT License | 6 votes |
/** * 兼容手动添加的证书文件 */ private void convertInfo() { if (!StrUtil.isEmpty(domain)) { return; } JSONObject jsonObject = decodeCert(getCert(), getKey()); if (jsonObject != null) { // 获取信息 this.setDomain(jsonObject.getString("domain")); this.setExpirationTime(jsonObject.getLongValue("expirationTime")); this.setEffectiveTime(jsonObject.getLongValue("effectiveTime")); // 数据持久化到文件中 CertService certService = SpringUtil.getBean(CertService.class); certService.updateItem(this); } }
Example 2
Source File: LinuxSystemCommander.java From Jpom with MIT License | 6 votes |
@Override public JSONObject getAllMonitor() { String result = CommandUtil.execSystemCommand("top -i -b -n 1"); if (StrUtil.isEmpty(result)) { return null; } String[] split = result.split(StrUtil.LF); int length = split.length; JSONObject jsonObject = new JSONObject(); if (length >= 2) { String cpus = split[2]; //cpu占比 String cpu = getLinuxCpu(cpus); jsonObject.put("cpu", cpu); } if (length >= 3) { String mem = split[3]; //内存占比 String memory = getLinuxMemory(mem); jsonObject.put("memory", memory); } jsonObject.put("disk", getHardDisk()); return jsonObject; }
Example 3
Source File: JwtTokenUtil.java From mall-swarm with Apache License 2.0 | 6 votes |
/** * 当原来的token没过期时是可以刷新的 * * @param oldToken 带tokenHead的token */ public String refreshHeadToken(String oldToken) { if(StrUtil.isEmpty(oldToken)){ return null; } String token = oldToken.substring(tokenHead.length()); if(StrUtil.isEmpty(token)){ return null; } //token校验不通过 Claims claims = getClaimsFromToken(token); if(claims==null){ return null; } //如果token已经过期,不支持刷新 if(isTokenExpired(token)){ return null; } //如果token在30分钟之内刚刷新过,返回原token if(tokenRefreshJustBefore(token,30*60)){ return token; }else{ claims.put(CLAIM_KEY_CREATED, new Date()); return generateToken(claims); } }
Example 4
Source File: AttachmentServiceImpl.java From SENS with GNU General Public License v3.0 | 6 votes |
/** * 七牛云删除附件 * * @param key key * @return boolean */ @Override public boolean deleteQiNiuAttachment(String key) { boolean flag = true; final Configuration cfg = new Configuration(Zone.zone0()); final String accessKey = SensConst.OPTIONS.get("qiniu_access_key"); final String secretKey = SensConst.OPTIONS.get("qiniu_secret_key"); final String bucket = SensConst.OPTIONS.get("qiniu_bucket"); if (StrUtil.isEmpty(accessKey) || StrUtil.isEmpty(secretKey) || StrUtil.isEmpty(bucket)) { return false; } final Auth auth = Auth.create(accessKey, secretKey); final BucketManager bucketManager = new BucketManager(auth, cfg); try { bucketManager.delete(bucket, key); } catch (QiniuException ex) { System.err.println(ex.code()); System.err.println(ex.response.toString()); flag = false; } return flag; }
Example 5
Source File: AttachmentServiceImpl.java From SENS with GNU General Public License v3.0 | 6 votes |
/** * 上传转发 * * @param file file * @param request request * @return Map */ @Override public Map<String, String> upload(MultipartFile file, HttpServletRequest request) { Map<String, String> resultMap; String attachLoc = SensConst.OPTIONS.get(BlogPropertiesEnum.ATTACH_LOC.getProp()); if (StrUtil.isEmpty(attachLoc)) { attachLoc = "server"; } switch (attachLoc) { case "qiniu": resultMap = this.attachQiNiuUpload(file, request); break; case "upyun": resultMap = this.attachUpYunUpload(file, request); break; default: resultMap = this.attachUpload(file, request); break; } return resultMap; }
Example 6
Source File: LogBackController.java From Jpom with MIT License | 6 votes |
@RequestMapping(value = "logBack_delete", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) public String clear(String name, String copyId) { name = pathSafe(name); if (StrUtil.isEmpty(name)) { return JsonMessage.getString(405, "非法操作:" + name); } ProjectInfoModel pim = getProjectInfoModel(); ProjectInfoModel.JavaCopyItem copyItem = pim.findCopyItem(copyId); File logBack = copyItem == null ? pim.getLogBack() : pim.getLogBack(copyItem); if (logBack.exists() && logBack.isDirectory()) { logBack = FileUtil.file(logBack, name); if (logBack.exists()) { FileUtil.del(logBack); return JsonMessage.getString(200, "删除成功"); } return JsonMessage.getString(500, "没有对应文件"); } else { return JsonMessage.getString(500, "没有对应文件夹"); } }
Example 7
Source File: PayController.java From supplierShop with MIT License | 6 votes |
@PostMapping(value = "/shop/pay-confirm-money") @ApiOperation(value = "支付前检测获取的价格",notes = "支付前检测获取的价格") public R confirmPayMoney(@Validated @RequestBody String jsonStr){ JSONObject jsonObject = JSON.parseObject(jsonStr); String orderNo = jsonObject.get("order_no").toString(); if(StrUtil.isEmpty(orderNo)){ return R.error(4000,"订单号缺失"); } int userId = userOperator.getUser().getId(); StoreOrder storeOrder = orderService.orderInfo(orderNo,userId); if(ObjectUtil.isNull(storeOrder)){ return R.error(4000,"订单不存在"); } Map<String,Object> map = new HashMap<>(); map.put("order_amount",storeOrder.getOrderAmount()); return R.success(map); }
Example 8
Source File: WhitelistDirectoryController.java From Jpom with MIT License | 5 votes |
private JsonMessage save(String project, List<String> certificate, List<String> nginx) { if (StrUtil.isEmpty(project)) { return new JsonMessage(401, "项目路径白名单不能为空"); } List<String> list = StrSpliter.splitTrim(project, StrUtil.LF, true); if (list == null || list.size() <= 0) { return new JsonMessage(401, "项目路径白名单不能为空"); } return save(list, certificate, nginx); }
Example 9
Source File: BaseForm.java From datax-web with MIT License | 5 votes |
/** * 获取页码 * * @return */ public Long getPageNo() { String pageNum = StrUtil.toString(this.get("current")); if (!StrUtil.isEmpty(pageNum) && NumberUtil.isNumber(pageNum)) { this.current = Long.parseLong(pageNum); } return this.current; }
Example 10
Source File: BaseForm.java From datax-web with MIT License | 5 votes |
/** * 解析分页排序参数(pageHelper) */ public void parsePagingQueryParams() { // 排序字段解析 String orderBy = StrUtil.toString(this.get("orderby")).trim(); String sortName = StrUtil.toString(this.get("sort")).trim(); String sortOrder = StrUtil.toString(this.get("order")).trim().toLowerCase(); if (StrUtil.isEmpty(orderBy) && !StrUtil.isEmpty(sortName)) { if (!sortOrder.equals("asc") && !sortOrder.equals("desc")) { sortOrder = "asc"; } this.set("orderby", sortName + " " + sortOrder); } }
Example 11
Source File: SystemConfigController.java From Jpom with MIT License | 5 votes |
@RequestMapping(value = "save_config.json", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) public String saveConfig(String content, String restart) { if (StrUtil.isEmpty(content)) { return JsonMessage.getString(405, "内容不能为空"); } try { YamlPropertySourceLoader yamlPropertySourceLoader = new YamlPropertySourceLoader(); ByteArrayResource resource = new ByteArrayResource(content.getBytes()); yamlPropertySourceLoader.load("test", resource); } catch (Exception e) { DefaultSystemLog.getLog().warn("内容格式错误,请检查修正", e); return JsonMessage.getString(500, "内容格式错误,请检查修正:" + e.getMessage()); } if (JpomManifest.getInstance().isDebug()) { return JsonMessage.getString(405, "调试模式不支持在线修改,请到resource目录下"); } File resourceFile = ExtConfigBean.getResourceFile(); FileUtil.writeString(content, resourceFile, CharsetUtil.CHARSET_UTF_8); if (Convert.toBool(restart, false)) { // 重启 ThreadUtil.execute(() -> { try { Thread.sleep(2000); } catch (InterruptedException ignored) { } JpomApplication.restart(); }); } return JsonMessage.getString(200, "修改成功"); }
Example 12
Source File: SocketSessionUtil.java From Jpom with MIT License | 5 votes |
public static void send(WebSocketSession session, String msg) throws IOException { if (StrUtil.isEmpty(msg)) { return; } if (!session.isOpen()) { throw new RuntimeException("session close "); } try { LOCK.lock(session.getId()); IOException exception = null; int tryCount = 0; do { tryCount++; if (exception != null) { // 上一次有异常、休眠 500 try { Thread.sleep(500); } catch (InterruptedException ignored) { } } try { session.sendMessage(new TextMessage(msg)); exception = null; break; } catch (IOException e) { DefaultSystemLog.getLog().error("发送消息失败:" + tryCount, e); exception = e; } } while (tryCount <= ERROR_TRY_COUNT); if (exception != null) { throw exception; } } finally { LOCK.unlock(session.getId()); } }
Example 13
Source File: AgentExtConfigBean.java From Jpom with MIT License | 5 votes |
/** * 创建请求对象 * * @param openApi url * @return HttpRequest * @see ServerOpenApi */ public HttpRequest createServerRequest(String openApi) { if (StrUtil.isEmpty(getServerUrl())) { throw new JpomRuntimeException("请先配置server端url"); } if (StrUtil.isEmpty(getServerToken())) { throw new JpomRuntimeException("请先配置server端Token"); } // 加密 String md5 = SecureUtil.md5(getServerToken()); md5 = SecureUtil.sha1(md5 + ServerOpenApi.HEAD); HttpRequest httpRequest = HttpUtil.createPost(String.format("%s%s", serverUrl, openApi)); httpRequest.header(ServerOpenApi.HEAD, md5); return httpRequest; }
Example 14
Source File: SshHandler.java From Jpom with MIT License | 5 votes |
@Override protected void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception { JSONObject jsonObject = JSONObject.parseObject(message.getPayload()); if (jsonObject.containsKey("resize")) { return; } String data = jsonObject.getString("data"); if (StrUtil.isEmpty(data)) { return; } HandlerItem handlerItem = HANDLER_ITEM_CONCURRENT_HASH_MAP.get(session.getId()); // 判断权限 if (this.checkCommand(handlerItem, data)) { return; } if ("\t".equals(data)) { this.sendCommand(handlerItem, data); return; } if (StrUtil.CR.equals(data)) { if (handlerItem.dataToDst.length() > 0) { data = StrUtil.CRLF; } } else { handlerItem.dataToDst.append(data); // 判断权限 if (this.checkCommand(handlerItem, null)) { return; } } this.sendCommand(handlerItem, data); if (!StrUtil.CRLF.equals(data) && !StrUtil.CR.equals(data)) { sendBinary(handlerItem.session, data); } }
Example 15
Source File: NginxController.java From Jpom with MIT License | 5 votes |
/** * 获取nginx状态 * * @return json */ @RequestMapping(value = "status", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) public String status() { String name = nginxService.getServiceName(); if (StrUtil.isEmpty(name)) { return JsonMessage.getString(500, "服务名错误"); } JSONObject jsonObject = new JSONObject(); jsonObject.put("name", name); boolean serviceStatus = AbstractSystemCommander.getInstance().getServiceStatus(name); jsonObject.put("status", serviceStatus); return JsonMessage.getString(200, "", jsonObject); }
Example 16
Source File: JpomManifest.java From Jpom with MIT License | 4 votes |
/** * 检查是否为jpom包 * * @param path 路径 * @param clsName 类名 * @return 结果消息 */ public static JsonMessage checkJpomJar(String path, Class clsName) { String version; File jarFile = new File(path); try (JarFile jarFile1 = new JarFile(jarFile)) { Manifest manifest = jarFile1.getManifest(); Attributes attributes = manifest.getMainAttributes(); String mainClass = attributes.getValue(Attributes.Name.MAIN_CLASS); if (mainClass == null) { return new JsonMessage(405, "清单文件中没有找到对应的MainClass属性"); } JarClassLoader jarClassLoader = JarClassLoader.load(jarFile); try { jarClassLoader.loadClass(mainClass); } catch (ClassNotFoundException notFound) { return new JsonMessage(405, "中没有找到对应的MainClass:" + mainClass); } ZipEntry entry = jarFile1.getEntry(StrUtil.format("BOOT-INF/classes/{}.class", StrUtil.replace(clsName.getName(), ".", "/"))); if (entry == null) { return new JsonMessage(405, "此包不是Jpom【" + JpomApplication.getAppType().name() + "】包"); } version = attributes.getValue(Attributes.Name.IMPLEMENTATION_VERSION); if (StrUtil.isEmpty(version)) { return new JsonMessage(405, "此包没有版本号"); } String timeStamp = attributes.getValue("Jpom-Timestamp"); if (StrUtil.isEmpty(timeStamp)) { return new JsonMessage(405, "此包没有版本号"); } timeStamp = parseJpomTime(timeStamp); if (StrUtil.equals(version, JpomManifest.getInstance().getVersion()) && StrUtil.equals(timeStamp, JpomManifest.getInstance().getTimeStamp())) { return new JsonMessage(405, "新包和正在运行的包一致"); } } catch (Exception e) { DefaultSystemLog.getLog().error("解析jar", e); return new JsonMessage(500, " 解析错误:" + e.getMessage()); } return new JsonMessage(200, version); }
Example 17
Source File: AttachmentServiceImpl.java From SENS with GNU General Public License v3.0 | 4 votes |
/** * 又拍云上传 * * @param file file * @param request request * @return Map */ @Override public Map<String, String> attachUpYunUpload(MultipartFile file, HttpServletRequest request) { final Map<String, String> resultMap = new HashMap<>(6); try { String key = "uploads/" + DateUtil.thisYear() + "/" + (DateUtil.thisMonth() + 1) + "/" + Md5Util.getMD5Checksum(file); final String ossSrc = SensConst.OPTIONS.get("upyun_oss_src"); final String ossPwd = SensConst.OPTIONS.get("upyun_oss_pwd"); final String bucket = SensConst.OPTIONS.get("upyun_oss_bucket"); final String domain = SensConst.OPTIONS.get("upyun_oss_domain"); final String operator = SensConst.OPTIONS.get("upyun_oss_operator"); final String smallUrl = SensConst.OPTIONS.get("upyun_oss_small"); if (StrUtil.isEmpty(ossSrc) || StrUtil.isEmpty(ossPwd) || StrUtil.isEmpty(domain) || StrUtil.isEmpty(bucket) || StrUtil.isEmpty(operator)) { return resultMap; } final String fileName = file.getOriginalFilename(); final String fileSuffix = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf('.')); final UpYun upYun = new UpYun(bucket, operator, ossPwd); upYun.setTimeout(60); upYun.setApiDomain(UpYun.ED_AUTO); upYun.setDebug(true); upYun.writeFile(ossSrc + key + fileSuffix, file.getBytes(), true, null); final String filePath = domain.trim() + ossSrc + key + fileSuffix; String smallPath = filePath; if (smallUrl != null) { smallPath += smallUrl; } final BufferedImage image = ImageIO.read(file.getInputStream()); if (image != null) { resultMap.put("wh", image.getWidth() + "x" + image.getHeight()); } resultMap.put("fileName", fileName); resultMap.put("filePath", filePath.trim()); resultMap.put("smallPath", smallPath.trim()); resultMap.put("suffix", fileSuffix); resultMap.put("size", SensUtils.parseSize(file.getSize())); resultMap.put("location", AttachLocationEnum.UPYUN.getValue()); } catch (Exception e) { e.printStackTrace(); } return resultMap; }
Example 18
Source File: MenuServiceImpl.java From zuihou-admin-cloud with Apache License 2.0 | 4 votes |
private List<Menu> menuListFilterGroup(String group, List<Menu> visibleMenu) { if (StrUtil.isEmpty(group)) { return visibleMenu; } return visibleMenu.stream().filter((menu) -> group.equals(menu.getGroup())).collect(Collectors.toList()); }
Example 19
Source File: ReactiveAddrUtil.java From microservices-platform with Apache License 2.0 | 4 votes |
private static boolean isEmptyIP(String ip) { if (StrUtil.isEmpty(ip) || UNKNOWN_STR.equalsIgnoreCase(ip)) { return true; } return false; }
Example 20
Source File: ProjectInfoModel.java From Jpom with MIT License | 3 votes |
/** * 创建进程标记 * * @param id * @param copyId * @return */ public static String getTagId(String id, String copyId) { if (StrUtil.isEmpty(copyId)) { return id; } return StrUtil.format("{}:{}", id, copyId); }