ExcuteConfigUtils.java 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package com.example.xiaoshiweixinback.business.utils;
  2. import com.alibaba.fastjson.JSONArray;
  3. import com.example.xiaoshiweixinback.XiaoshiWeixinbackApplication;
  4. import com.example.xiaoshiweixinback.entity.vo.PatentExportVO;
  5. import org.springframework.boot.system.ApplicationHome;
  6. import org.springframework.stereotype.Service;
  7. import java.io.*;
  8. import java.nio.charset.StandardCharsets;
  9. import java.util.List;
  10. /**
  11. * 解析配置utils
  12. *
  13. * @Author xiexiang
  14. * @Date 2023/6/2
  15. */
  16. @Service
  17. public class ExcuteConfigUtils {
  18. public static final String FILE_SEPARATOR = System.getProperty("file.separator");
  19. //解析配置utils
  20. public static String excuteConfigJson() {
  21. ApplicationHome ah = new ApplicationHome(XiaoshiWeixinbackApplication.class);
  22. File file = ah.getSource();
  23. String rootPath = file.getParentFile().toString() + FILE_SEPARATOR + "patentExport.json";
  24. BufferedReader reader = null;
  25. StringBuilder last = new StringBuilder();
  26. InputStreamReader inputStreamReader;
  27. try (FileInputStream fileInputStream = new FileInputStream(rootPath)) {
  28. inputStreamReader = new InputStreamReader(fileInputStream, StandardCharsets.UTF_8);
  29. reader = new BufferedReader(inputStreamReader);
  30. String tempString;
  31. while ((tempString = reader.readLine()) != null) {
  32. last.append(tempString);
  33. }
  34. reader.close();
  35. } catch (IOException e) {
  36. e.printStackTrace();
  37. } finally {
  38. if (reader != null) {
  39. try {
  40. reader.close();
  41. } catch (IOException e) {
  42. e.printStackTrace();
  43. }
  44. }
  45. }
  46. return last.toString();
  47. }
  48. //解析配置utils
  49. public static List<PatentExportVO> excuteConfigVO() {
  50. String config = ExcuteConfigUtils.excuteConfigJson();
  51. List<PatentExportVO> patentExportVOS = JSONArray.parseArray(config,PatentExportVO.class);
  52. return patentExportVOS;
  53. }
  54. }