FileTest.java 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. package com.xjrsoft.xjrsoftboot;
  2. import cn.hutool.core.util.IdUtil;
  3. import com.google.gson.JsonArray;
  4. import com.xjrsoft.module.schedule.util.ScheduleUtil;
  5. import org.junit.jupiter.api.Test;
  6. import java.io.BufferedReader;
  7. import java.io.DataInputStream;
  8. import java.io.FileInputStream;
  9. import java.io.FileReader;
  10. import java.io.IOException;
  11. import java.nio.charset.StandardCharsets;
  12. import java.time.LocalDate;
  13. import java.time.format.DateTimeFormatter;
  14. import java.time.temporal.ChronoUnit;
  15. import java.util.Arrays;
  16. import java.util.Base64;
  17. import java.util.List;
  18. /**
  19. * @author dzx
  20. * @date 2023/12/4
  21. */
  22. public class FileTest {
  23. @Test
  24. void param() throws Exception {
  25. long timestamp = System.currentTimeMillis();
  26. System.out.println("timestamp:" + timestamp);
  27. //生成签名
  28. String sign = ScheduleUtil.createSign(timestamp);
  29. System.out.println("sign:" + sign);
  30. String startDateStr = "2024-07-29", endDateStr = "2024-08-16";
  31. LocalDate startDateObj = LocalDate.parse(startDateStr);
  32. LocalDate endDateObj = LocalDate.parse(endDateStr);
  33. long between = ChronoUnit.DAYS.between(startDateObj, endDateObj);
  34. long times = (between / 7) + 1;
  35. DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
  36. for (int i = 0; i < times; i ++) {
  37. LocalDate statrTime = startDateObj.plusDays(i * 7L);
  38. String startDate = statrTime.format(formatter);
  39. LocalDate endTime = statrTime.plusDays(6L);
  40. if(endTime.isAfter(endDateObj)){
  41. endTime = endDateObj;
  42. }
  43. String endDate = endTime.format(formatter);
  44. System.out.println("i =====================================-> " + i);
  45. System.out.println("startDate -> " + startDate);
  46. System.out.println("endDate -> " + endDate);
  47. }
  48. }
  49. @Test
  50. void idTest() throws Exception {
  51. System.out.println(IdUtil.getSnowflakeNextId());
  52. String str = "[{\"label\":\"早自习课时单价:正式聘用\",\"field\":\"cost1\",\"value\":22},{\"label\":\"非正式聘用\",\"field\":\"cost2\",\"value\":33},{\"label\":\"正课课时单价:正式聘用\",\"field\":\"cost3\",\"value\":44},{\"label\":\"非正式聘用\",\"field\":\"cost4\",\"value\":43},{\"label\":\"晚自习课时单价:正式聘用\",\"field\":\"cost5\",\"value\":55},{\"label\":\"非正式聘用\",\"field\":\"cost6\",\"value\":134},{\"label\":\"超出课时单价:正式聘用\",\"field\":\"cost7\",\"value\":66},{\"label\":\"非正式聘用\",\"field\":\"cost8\",\"value\":13},{\"label\":\"超出课时标准(每周):正式聘用\",\"field\":\"cost9\",\"value\":77},{\"label\":\"非正式聘用\",\"field\":\"cost10\",\"value\":12},{\"label\":\"顶课课时单价:正式聘用\",\"field\":\"cost11\",\"value\":88},{\"label\":\"非正式聘用\",\"field\":\"cost12\",\"value\":99}]";
  53. }
  54. @Test
  55. void idTest2() throws Exception {
  56. String timeNumbers = "5,6,7";
  57. Arrays.asList(timeNumbers.split(","));
  58. }
  59. @Test
  60. void idTest3() throws Exception {
  61. String filePath = "C:\\Users\\14263\\Desktop\\七日杀mod\\虹彩+隐匿的曙光\\item_modifiers.txt";
  62. try (BufferedReader reader = new BufferedReader(new FileReader(filePath))) {
  63. // 读取文件内容
  64. StringBuilder base64ContentBuilder = new StringBuilder();
  65. String currentLine;
  66. while ((currentLine = reader.readLine()) != null) {
  67. base64ContentBuilder.append(currentLine);
  68. }
  69. // 获取完整的 Base64 编码字符串
  70. String base64EncodedString = base64ContentBuilder.toString();
  71. // 解码 Base64 字符串
  72. byte[] decodedBytes = Base64.getDecoder().decode(base64EncodedString);
  73. // 将解码后的字节数组转换为字符串(如果原内容是文本)
  74. String decodedString = new String(decodedBytes, StandardCharsets.UTF_8);
  75. // 输出解码后的内容
  76. System.out.println("Decoded content:");
  77. System.out.println(decodedString);
  78. // 如果解码后的数据是二进制文件(如图片、PDF等),可以将其保存为文件
  79. // saveDecodedDataAsFile(decodedBytes, "output_file_path");
  80. } catch (IOException e) {
  81. e.printStackTrace();
  82. }
  83. }
  84. }