|
@@ -10,10 +10,7 @@ import kd.bos.servicehelper.AttachmentServiceHelper;
|
|
|
import kd.bos.servicehelper.BusinessDataServiceHelper;
|
|
|
import okhttp3.*;
|
|
|
|
|
|
-import java.io.ByteArrayInputStream;
|
|
|
-import java.io.ByteArrayOutputStream;
|
|
|
-import java.io.IOException;
|
|
|
-import java.io.InputStream;
|
|
|
+import java.io.*;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
@@ -24,26 +21,47 @@ public class FileSECUtils {
|
|
|
|
|
|
String entryEntityName = "nckd_filetest";
|
|
|
|
|
|
- DynamicObject billByn = BusinessDataServiceHelper.loadSingle(entryEntityName,
|
|
|
- new QFilter[]{new QFilter("billno", QCP.equals, "test0001")});
|
|
|
-
|
|
|
- List<Map<String, Object>> sourceFileList = AttachmentServiceHelper.getAttachments(entryEntityName,billByn.getPkValue(), "attachmentpanel");
|
|
|
- //Map<String, InputStream> files = new HashMap<>();
|
|
|
-
|
|
|
- if(sourceFileList != null && sourceFileList.size()>0)
|
|
|
- {
|
|
|
- for(Map<String,Object> fileMap : sourceFileList){
|
|
|
- AttachmentDto attachmentDto = AttachmentServiceHelper.getAttachmentInfoByAttPk(fileMap.get("attPkId"));
|
|
|
- String fileUrl= attachmentDto.getResourcePath();
|
|
|
- String fileName = attachmentDto.getFilename();
|
|
|
- System.out.println("fileUrl:" + fileUrl+ ",fileName:"+fileName);
|
|
|
- ByteArrayOutputStream out = new ByteArrayOutputStream();
|
|
|
- FileServiceFactory.getAttachmentFileService().download(fileUrl, out, null);
|
|
|
- System.out.println("file:" + out.toByteArray());
|
|
|
- return out.toByteArray();
|
|
|
- //InputStream in = new ByteArrayInputStream(out.toByteArray());
|
|
|
- //files.put(fileUrl,in);
|
|
|
+// DynamicObject billByn = BusinessDataServiceHelper.loadSingle(entryEntityName,
|
|
|
+// new QFilter[]{new QFilter("billno", QCP.equals, "test0001")});
|
|
|
+//
|
|
|
+// List<Map<String, Object>> sourceFileList = AttachmentServiceHelper.getAttachments(entryEntityName,billByn.getPkValue(), "attachmentpanel");
|
|
|
+// Map<String, InputStream> files = new HashMap<>();
|
|
|
+//
|
|
|
+// if(sourceFileList != null && sourceFileList.size()>0)
|
|
|
+// {
|
|
|
+// for(Map<String,Object> fileMap : sourceFileList){
|
|
|
+// //AttachmentDto attachmentDto = AttachmentServiceHelper.getAttachmentInfoByAttPk(fileMap.get("attPkId"));
|
|
|
+// //String fileUrl= attachmentDto.getResourcePath();
|
|
|
+// //String fileName = attachmentDto.getFilename();
|
|
|
+//
|
|
|
+//
|
|
|
+//
|
|
|
+// System.out.println("fileUrl:" + fileUrl+ ",fileName:"+fileName);
|
|
|
+// ByteArrayOutputStream out = new ByteArrayOutputStream();
|
|
|
+// FileServiceFactory.getAttachmentFileService().download(fileUrl, out, null);
|
|
|
+// System.out.println("file:" + out.toByteArray());
|
|
|
+// return out.toByteArray();
|
|
|
+// //InputStream in = new ByteArrayInputStream(out.toByteArray());
|
|
|
+// //files.put(fileUrl,in);
|
|
|
+// }
|
|
|
+// }
|
|
|
+
|
|
|
+ String filePath = "C:\\Users\\Administrator\\Desktop\\test.txt";
|
|
|
+ try (InputStream inputStream = new FileInputStream(filePath)) {
|
|
|
+ byte[] buffer = new byte[1024];
|
|
|
+ int bytesRead;
|
|
|
+
|
|
|
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
|
|
+
|
|
|
+ while ((bytesRead = inputStream.read(buffer)) != -1) {
|
|
|
+ outputStream.write(buffer, 0, bytesRead);
|
|
|
}
|
|
|
+ // 如果需要,可以在这里对 outputStream 进行额外操作
|
|
|
+ // 例如:outputStream.flush();
|
|
|
+ return outputStream.toByteArray();
|
|
|
+
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
}
|
|
|
return null;
|
|
|
}
|