-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copywriter.java
58 lines (48 loc) · 1.59 KB
/
Copywriter.java
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package com.yurii.salimov.lesson05.task07;
import java.io.*;
import java.util.Vector;
/**
* @author Yuriy Salimov ([email protected])
* @version 1.0
*/
public class Copywriter {
private final static int BUF_SIZE = 2048;
private final String path;
public Copywriter(final String path) {
this.path = path;
}
public void copy() throws IOException {
final File directory = new File(this.path);
checkDir(directory);
copy(loadVector(directory), this.path);
}
public String getPath() {
return this.path;
}
private static void checkDir(final File directory) {
if (!directory.exists()) {
directory.mkdirs();
}
}
private static Vector loadVector(final File directory) throws FileNotFoundException {
Vector vector = new Vector();
for (File file : directory.listFiles()) {
vector.addElement(new FileInputStream(file));
}
return vector;
}
private static void copy(final Vector vector, final String path) throws IOException {
try (SequenceInputStream sis = new SequenceInputStream(vector.elements());
FileOutputStream fos = new FileOutputStream(path + "\\" + "OUT.txt");
BufferedOutputStream bos = new BufferedOutputStream(fos)) {
final byte[] buf = new byte[BUF_SIZE];
int size;
do {
size = sis.read(buf, 0, buf.length);
if (size > 0) {
bos.write(buf, 0, size);
}
} while (size > 0);
}
}
}