-
Notifications
You must be signed in to change notification settings - Fork 1
/
CopyFile.java
51 lines (43 loc) · 1.48 KB
/
CopyFile.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
package com.yurii.salimov.lesson06.task05;
import java.io.*;
/**
* @author Yuriy Salimov ([email protected])
* @version 1.0
*/
public final class CopyFile implements Runnable {
private final File inFile;
private final File outFile;
private final int number;
public CopyFile(final String inFile, final String outFile, final int number) {
this.inFile = new File(inFile);
this.outFile = new File(outFile);
this.number = number;
}
@Override
public void run() {
if (this.inFile.exists() && this.inFile.isFile()) {
try (final InputStream inputStream = new FileInputStream(this.inFile);
final OutputStream outputStream = new FileOutputStream(this.outFile);) {
final long size = this.inFile.length() / this.number + 1;
final Block block = new Block(inputStream, outputStream, size);
createThreads(block, this.number);
Thread.sleep(100);
} catch (Exception ex) {
ex.getMessage();
}
} else {
System.out.println("The specified file is not available!");
}
}
public File getInputFile() {
return this.inFile;
}
public File getOutputFile() {
return this.outFile;
}
private static void createThreads(final Runnable runnable, final int number) {
for (int i = 0; i < number; i++) {
new Thread(runnable).start();
}
}
}