forked from wemakebug/FileUpload.Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMergeFile.java
More file actions
43 lines (34 loc) · 1.36 KB
/
MergeFile.java
File metadata and controls
43 lines (34 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package com.zhangzhihao.FileUpload.Java.Utils;
import org.jetbrains.annotations.NotNull;
import java.io.*;
import static com.zhangzhihao.FileUpload.Java.Utils.DeleteFolder.deleteFolder;
import static com.zhangzhihao.FileUpload.Java.Utils.StreamUtil.saveStreamToFile;
public class MergeFile {
/**
* @param chunksNumber
* @param ext
* @param guid
* @param uploadFolderPath
* @throws Exception
*/
public static void mergeFile(final int chunksNumber,
@NotNull final String ext,
@NotNull final String guid,
@NotNull final String uploadFolderPath)
throws Exception {
/*合并输入流*/
String mergePath = uploadFolderPath + guid + "/";
SequenceInputStream s ;
InputStream s1 = new FileInputStream(mergePath + 0 + ext);
InputStream s2 = new FileInputStream(mergePath + 1 + ext);
s = new SequenceInputStream(s1, s2);
for (int i = 2; i < chunksNumber; i++) {
InputStream s3 = new FileInputStream(mergePath + i + ext);
s = new SequenceInputStream(s, s3);
}
//通过输出流向文件写入数据
saveStreamToFile(s, uploadFolderPath + guid + ext);
//删除保存分块文件的文件夹
deleteFolder(mergePath);
}
}