yangys
2025-09-25 31ecdb8c700529a59dd762f0c47f0ed9c66d5092
blade-service/blade-mdm/src/main/java/org/springblade/mdm/utils/FileContentUtil.java
@@ -104,11 +104,10 @@
      byte[] buffer = new byte[2048];
      try {
         int actRead = inputStream.read(buffer);
         detector.handleData(buffer, 0, actRead);
         //识别结束必须调用这个方法
         detector.dataEnd();
         detector.reset();
      } catch (IOException e) {
         throw new RuntimeException(e);
      }
@@ -191,4 +190,20 @@
      }
      return new ByteArrayInputStream(Files.newInputStream(tempFile).readAllBytes());
    }
   public static List<String> readFirstNLines(InputStream inputStream, int n) throws IOException {
      List<String> lines = new ArrayList<>();
      try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) {
         String line;
         int count = 0;
         while ((line = reader.readLine()) != null && count < n) {
            lines.add(line);
            count++;
         }
      }
      return lines;
   }
}