解析命令行

import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

@SpringBootApplication
@MapperScan("com.aaa.mapper") // 这里替换为你的mapper接口所在的包名
public class MyApplication implements CommandLineRunner {

@Autowired
private FileContentService fileContentService;
public static void main(String[] args) {
SpringApplication.run(PgTestApplication.class, args);
}

@Override
public void run(String... args) throws Exception {
// read data
final List<FileContent> all = fileContentService.findAll();

System.out.println(all.size());
for (FileContent fileContent : all) {
final String path = fileContent.getPath();
if(path.contains("process")) {
final String content = fileContent.getContent();
// System.out.println(content);
if(null != content && content.startsWith("[")) {
final JSONArray objects = JSONUtil.parseArray(content);
objects.forEach(o -> {
JSONObject jsonObject = (JSONObject) o;
String name = jsonObject.getStr("name");
if(name.equalsIgnoreCase("w3wp.exe")) {
String commandLine = jsonObject.getStr("commandline");
System.out.println("=====================" + commandLine);
Pattern pattern = Pattern.compile("[^\\s\"']+|\"([^\"]*)\"|'([^']*)'");
Matcher matcher = pattern.matcher(commandLine);
while (matcher.find()) {
if (matcher.group(1) != null) {
System.out.println(matcher.group(1));
} else if (matcher.group(2) != null) {
System.out.println(matcher.group(2));
} else {
System.out.println(matcher.group());
}
}


}
});
}

}

if(path.contains("SConfig.xml")) {
final String content = fileContent.getContent();
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
// Document doc = dBuilder.parse(inputFile);
InputSource is = new InputSource(new StringReader(content));
Document doc = dBuilder.parse(is);
doc.getDocumentElement().normalize();

System.out.println("Root element: " + doc.getDocumentElement().getNodeName());
XMLParser.traverseNodes(doc.getDocumentElement(), 0); // 从根节点开始遍历
}

}
}
}

正则表达式[^\\s\"']+|\"([^\"]*)\"|'([^']*)'用于匹配不包含空格、单引号和双引号的字符串,或者包含在单引号或双引号中的字符串。

  • 3
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值