From 44b55dd34d09090fe6fdeb7d2428efe9e775424c Mon Sep 17 00:00:00 2001
From: yangys <y_ys79@sina.com>
Date: 星期三, 13 八月 2025 22:54:14 +0800
Subject: [PATCH] 增加流程文件下载接口
---
blade-service/blade-mdm/src/main/java/org/springblade/mdm/utils/FileContentUtil.java | 41 ++++++++++++++++++++++++++++++++++++++++-
1 files changed, 40 insertions(+), 1 deletions(-)
diff --git a/blade-service/blade-mdm/src/main/java/org/springblade/mdm/utils/FileContentUtil.java b/blade-service/blade-mdm/src/main/java/org/springblade/mdm/utils/FileContentUtil.java
index 1ea63b1..f29bbdd 100644
--- a/blade-service/blade-mdm/src/main/java/org/springblade/mdm/utils/FileContentUtil.java
+++ b/blade-service/blade-mdm/src/main/java/org/springblade/mdm/utils/FileContentUtil.java
@@ -89,7 +89,7 @@
public static String detectFromInputStream(InputStream inputStream) {
UniversalDetector detector = new UniversalDetector(null);
//寮�濮嬬粰涓�閮ㄥ垎鏁版嵁锛岃瀛︿範涓�涓嬪晩锛屽畼鏂瑰缓璁槸1000涓猙yte宸﹀彸锛堝綋鐒惰繖1000涓猙yte浣犲緱鍖呭惈涓枃涔嬬被鐨勶級
- byte[] buffer = new byte[1024];
+ byte[] buffer = new byte[2048];
try {
int actRead = inputStream.read(buffer);
@@ -104,4 +104,43 @@
return detector.getDetectedCharset();
}
+ /**
+ * 璇诲彇鏂囦欢鏌愯
+ * @param inputStream
+ * @param lineIndex 琛岀储寮� 0based
+ * @return 琛屾枃鏈�
+ * @throws IOException
+ */
+ public static String readLineAt(InputStream inputStream,int lineIndex) throws IOException {
+ byte[] bytes = inputStream.readAllBytes();
+ ByteArrayInputStream byteStream = new ByteArrayInputStream(bytes);
+ Charset charset = Charsets.charset(detectFromInputStream(byteStream));
+ byteStream.reset();//閲嶇疆锛屼娇缁х画鍙敤
+
+ String lineText = "";
+ try (BufferedReader reader = new BufferedReader(new InputStreamReader(byteStream,charset))) {
+ // 璺宠繃绗竴琛�
+ int current = 0;
+ while(current<=lineIndex && lineText!=null) {
+ lineText = reader.readLine();
+ current++;
+ }
+ }
+ return lineText;
+ }
+
+ /**
+ * 浠庤緭鍏ユ祦鑾峰彇鏂囨湰
+ * @param ins 鏉熸祦
+ * @return 鏂囨湰瀛楃
+ * @throws IOException
+ */
+ public static String getContentFromStream(InputStream ins) throws IOException {
+ byte[] bytes = ins.readAllBytes();
+ ByteArrayInputStream byteStream = new ByteArrayInputStream(bytes);
+ Charset charset = Charsets.charset(detectFromInputStream(byteStream));
+ byteStream.reset();//閲嶇疆锛屼娇缁х画鍙敤
+
+ return new String(bytes, charset);
+ }
}
--
Gitblit v1.9.3