Java Code Examples for cn.hutool.core.convert.Convert#toInt()
The following examples show how to use
cn.hutool.core.convert.Convert#toInt() .
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: LinuxSystemCommander.java From Jpom with MIT License | 6 votes |
@Override public String stopService(String serviceName) { if (StrUtil.startWith(serviceName, StrUtil.SLASH)) { String ps = getPs(serviceName); List<String> list = StrUtil.splitTrim(ps, StrUtil.LF); if (list == null || list.isEmpty()) { return "stop"; } String s = list.get(0); list = StrUtil.splitTrim(s, StrUtil.SPACE); if (list == null || list.size() < 2) { return "stop"; } File file = new File(SystemUtil.getUserInfo().getHomeDir()); int pid = Convert.toInt(list.get(1), 0); if (pid <= 0) { return "error stop"; } return kill(file, pid); } String format = StrUtil.format("service {} stop", serviceName); return CommandUtil.execSystemCommand(format); }
Example 2
Source File: JvmUtil.java From Jpom with MIT License | 6 votes |
/** * 获取jmx 服务对象,如果没有加载则加载对应插件 * * @param virtualMachine virtualMachine * @return JMXServiceURL * @throws IOException IO * @throws AgentLoadException 插件加载 * @throws AgentInitializationException 插件初始化 */ private static JMXServiceURL getJMXServiceURL(VirtualMachine virtualMachine) throws IOException, AgentLoadException, AgentInitializationException, ClassNotFoundException { try { String address = virtualMachine.getAgentProperties().getProperty("com.sun.management.jmxremote.localConnectorAddress"); if (address != null) { return new JMXServiceURL(address); } int pid = Convert.toInt(virtualMachine.id()); address = importFrom(pid); if (address != null) { return new JMXServiceURL(address); } String agent = getManagementAgent(); virtualMachine.loadAgent(agent); address = virtualMachine.getAgentProperties().getProperty("com.sun.management.jmxremote.localConnectorAddress"); if (address != null) { return new JMXServiceURL(address); } return null; } catch (InternalError internalError) { DefaultSystemLog.getLog().error("jmx 异常", internalError); return null; } }
Example 3
Source File: AbstractProjectCommander.java From Jpom with MIT License | 5 votes |
/** * 获取进程占用的主要端口 * * @param pid 进程id * @return 端口 */ public String getMainPort(int pid) { String cachePort = PID_PORT.get(pid); if (cachePort != null) { return cachePort; } List<NetstatModel> list = listNetstat(pid, true); if (list == null) { return StrUtil.DASHED; } List<Integer> ports = new ArrayList<>(); for (NetstatModel model : list) { String local = model.getLocal(); String portStr = getPortFormLocalIp(local); if (portStr == null) { continue; } // 取最小的端口号 int minPort = Convert.toInt(portStr, Integer.MAX_VALUE); if (minPort == Integer.MAX_VALUE) { continue; } ports.add(minPort); } if (CollUtil.isEmpty(ports)) { return StrUtil.DASHED; } String allPort = CollUtil.join(ports, ","); // 缓存 PID_PORT.put(pid, allPort); return allPort; }
Example 4
Source File: AbstractProjectCommander.java From Jpom with MIT License | 5 votes |
/** * 转换pid * * @param result 查询信息 * @return int */ public static int parsePid(String result) { if (result.startsWith(AbstractProjectCommander.RUNNING_TAG)) { return Convert.toInt(result.split(":")[1]); } return 0; }
Example 5
Source File: SmsTencentStrategy.java From zuihou-admin-boot with Apache License 2.0 | 5 votes |
@Override protected SmsResult send(SmsDO smsDO) { try { //初始化单发 SmsSingleSender singleSender = new SmsSingleSender(Convert.toInt(smsDO.getAppId(), 0), smsDO.getAppSecret()); String paramStr = smsDO.getTemplateParams(); JSONObject param = JSONObject.parseObject(paramStr, Feature.OrderedField); Set<Map.Entry<String, Object>> sets = param.entrySet(); ArrayList<String> paramList = new ArrayList<>(); for (Map.Entry<String, Object> val : sets) { paramList.add(val.getValue().toString()); } SmsSingleSenderResult singleSenderResult = singleSender.sendWithParam("86", smsDO.getPhone(), Convert.toInt(smsDO.getTemplateCode()), paramList, smsDO.getSignName(), "", ""); log.info("tencent result={}", singleSenderResult.toString()); return SmsResult.build(ProviderType.TENCENT, String.valueOf(singleSenderResult.result), singleSenderResult.sid, singleSenderResult.ext, ERROR_CODE_MAP.getOrDefault(String.valueOf(singleSenderResult.result), singleSenderResult.errMsg), singleSenderResult.fee); } catch (Exception e) { log.error(e.getMessage()); return SmsResult.fail(e.getMessage()); } }
Example 6
Source File: SmsTencentStrategy.java From zuihou-admin-cloud with Apache License 2.0 | 5 votes |
@Override protected SmsResult send(SmsDO smsDO) { try { //初始化单发 SmsSingleSender singleSender = new SmsSingleSender(Convert.toInt(smsDO.getAppId(), 0), smsDO.getAppSecret()); String paramStr = smsDO.getTemplateParams(); JSONObject param = JSONObject.parseObject(paramStr, Feature.OrderedField); Set<Map.Entry<String, Object>> sets = param.entrySet(); ArrayList<String> paramList = new ArrayList<>(); for (Map.Entry<String, Object> val : sets) { paramList.add(val.getValue().toString()); } SmsSingleSenderResult singleSenderResult = singleSender.sendWithParam("86", smsDO.getPhone(), Convert.toInt(smsDO.getTemplateCode()), paramList, smsDO.getSignName(), "", ""); log.info("tencent result={}", singleSenderResult.toString()); return SmsResult.build(ProviderType.TENCENT, String.valueOf(singleSenderResult.result), singleSenderResult.sid, singleSenderResult.ext, ERROR_CODE_MAP.getOrDefault(String.valueOf(singleSenderResult.result), singleSenderResult.errMsg), singleSenderResult.fee); } catch (Exception e) { log.error(e.getMessage()); return SmsResult.fail(e.getMessage()); } }
Example 7
Source File: ContextUtils.java From v-mock with MIT License | 4 votes |
/** * 获取Integer参数 */ public static Integer getParameterToInt(String name) { return Convert.toInt(getRequest().getParameter(name)); }
Example 8
Source File: WindowsSystemCommander.java From Jpom with MIT License | 4 votes |
/** * 将windows的tasklist转为集合 * * @param header 是否包含投信息 * @param result 进程信息 * @return jsonArray */ private static List<ProcessModel> formatWindowsProcess(String result, boolean header) { List<String> list = StrSpliter.splitTrim(result, StrUtil.LF, true); if (list.isEmpty()) { return null; } List<ProcessModel> processModels = new ArrayList<>(); ProcessModel processModel; for (int i = header ? 2 : 0, len = list.size(); i < len; i++) { String param = list.get(i); List<String> memList = StrSpliter.splitTrim(param, StrUtil.SPACE, true); processModel = new ProcessModel(); int pid = Convert.toInt(memList.get(1), 0); processModel.setPid(pid); // String name = memList.get(0); processModel.setCommand(name); //使用内存 kb String mem = memList.get(4).replace(",", ""); long aLong = Convert.toLong(mem, 0L); // FileUtil.readableFileSize() processModel.setRes(aLong / 1024 + " MB"); String status = memList.get(6); processModel.setStatus(formatStatus(status)); // processModel.setUser(memList.get(7)); processModel.setTime(memList.get(8)); try { OperatingSystemMXBean operatingSystemMXBean = JvmUtil.getOperatingSystemMXBean(memList.get(1)); if (operatingSystemMXBean != null) { //最近jvm cpu使用率 double processCpuLoad = operatingSystemMXBean.getProcessCpuLoad() * 100; if (processCpuLoad <= 0) { processCpuLoad = 0; } processModel.setCpu(String.format("%.2f", processCpuLoad) + "%"); //服务器总内存 long totalMemorySize = operatingSystemMXBean.getTotalPhysicalMemorySize(); BigDecimal total = new BigDecimal(totalMemorySize / 1024); // 进程 double v = new BigDecimal(aLong).divide(total, 4, BigDecimal.ROUND_HALF_UP).doubleValue() * 100; processModel.setMem(String.format("%.2f", v) + "%"); } } catch (Exception ignored) { } processModels.add(processModel); } return processModels; }
Example 9
Source File: BuildHistoryController.java From Jpom with MIT License | 4 votes |
@RequestMapping(value = "history_list.json", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) @ResponseBody @Feature(method = MethodFeature.LOG) public String historyList(String status, @ValidatorConfig(value = { @ValidatorItem(value = ValidatorRule.POSITIVE_INTEGER, msg = "limit error") }, defaultVal = "10") int limit, @ValidatorConfig(value = { @ValidatorItem(value = ValidatorRule.POSITIVE_INTEGER, msg = "page error") }, defaultVal = "1") int page, String buildDataId) { Page pageObj = new Page(page, limit); Entity entity = Entity.create(); // this.doPage(pageObj, entity, "startTime"); BaseEnum anEnum = null; if (StrUtil.isNotEmpty(status)) { Integer integer = Convert.toInt(status); if (integer != null) { anEnum = BaseEnum.getEnum(BuildModel.Status.class, integer); } } if (anEnum != null) { entity.set("status", anEnum.getCode()); } if (StrUtil.isNotBlank(buildDataId)) { entity.set("buildDataId", buildDataId); } PageResult<BuildHistoryLog> pageResult = dbBuildHistoryLogService.listPage(entity, pageObj); List<BuildHistoryLogVo> buildHistoryLogVos = new ArrayList<>(); pageResult.forEach(buildHistoryLog -> { BuildHistoryLogVo historyLogVo = new BuildHistoryLogVo(); BeanUtil.copyProperties(buildHistoryLog, historyLogVo); String dataId = buildHistoryLog.getBuildDataId(); BuildModel item = buildService.getItem(dataId); if (item != null) { historyLogVo.setBuildName(item.getName()); } buildHistoryLogVos.add(historyLogVo); }); JSONObject jsonObject = JsonMessage.toJson(200, "获取成功", buildHistoryLogVos); jsonObject.put("total", pageResult.getTotal()); return jsonObject.toString(); }
Example 10
Source File: BuildManageController.java From Jpom with MIT License | 4 votes |
/** * 获取构建的日志 * * @param id id * @param buildId 构建编号 * @param line 需要获取的行号 * @return json */ @RequestMapping(value = "getNowLog.json", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) @Feature(method = MethodFeature.EXECUTE) public String getNowLog(@ValidatorItem(value = ValidatorRule.NOT_BLANK, msg = "没有数据") String id, @ValidatorItem(value = ValidatorRule.POSITIVE_INTEGER, msg = "没有buildId") int buildId, @ValidatorItem(value = ValidatorRule.POSITIVE_INTEGER, msg = "line") int line) { BuildModel item = buildService.getItem(id); if (item == null) { return JsonMessage.getString(404, "没有对应数据"); } if (buildId > item.getBuildId()) { return JsonMessage.getString(405, "还没有对应的构建记录"); } File file = BuildUtil.getLogFile(item.getId(), buildId); if (file.isDirectory()) { return JsonMessage.getString(300, "日志文件错误"); } if (!file.exists()) { if (buildId == item.getBuildId()) { return JsonMessage.getString(201, "还没有日志文件"); } return JsonMessage.getString(300, "日志文件不存在"); } JSONObject data = new JSONObject(); // 运行中 data.put("run", item.getStatus() == BuildModel.Status.Ing.getCode() || item.getStatus() == BuildModel.Status.PubIng.getCode()); // 构建中 data.put("buildRun", item.getStatus() == BuildModel.Status.Ing.getCode()); // 读取文件 int linesInt = Convert.toInt(line, 1); LimitQueue<String> lines = new LimitQueue<>(500); final int[] readCount = {0}; FileUtil.readLines(file, CharsetUtil.CHARSET_UTF_8, (LineHandler) line1 -> { readCount[0]++; if (readCount[0] < linesInt) { return; } lines.add(line1); }); // 下次应该获取的行数 data.put("line", readCount[0] + 1); data.put("getLine", linesInt); data.put("dataLines", lines); return JsonMessage.getString(200, "ok", data); }
Example 11
Source File: ServletUtils.java From RuoYi with Apache License 2.0 | 4 votes |
/** * 获取Integer参数 */ public static Integer getParameterToInt(String name) { return Convert.toInt(getRequest().getParameter(name)); }
Example 12
Source File: ServletUtils.java From RuoYi with Apache License 2.0 | 4 votes |
/** * 获取Integer参数 */ public static Integer getParameterToInt(String name, Integer defaultValue) { return Convert.toInt(getRequest().getParameter(name), defaultValue); }
Example 13
Source File: Kv.java From magic-starter with GNU Lesser General Public License v3.0 | 2 votes |
/** * 获得特定类型值 * * @param attr 字段名 * @return 字段值 */ public Integer getInt(String attr) { return Convert.toInt(get(attr), -1); }
Example 14
Source File: JSONObject.java From RuoYi with Apache License 2.0 | 2 votes |
/** * 获取指定字段的整数值。如果字段不存在,或者无法转换为整数,返回defaultValue。 * * @param name 字段名,支持多级。 * @param defaultValue 查询失败时,返回的值。 * @return 返回指定的整数值,或者defaultValue。 */ public Integer intValue(final String name, final Integer defaultValue) { return Convert.toInt(intValue(name), defaultValue); }
Example 15
Source File: JSONObject.java From RuoYi with Apache License 2.0 | 2 votes |
/** * 返回字段整数值。如果不存在,返回defaultValue。 * * @param name 字段名。 * @param defaultValue 字段不存在时,返回的值。 * @return 返回指定字段整数值。 */ public Integer getInt(final String name, Integer defaultValue) { return Convert.toInt(getInt(name), defaultValue); }