forked from Kotlin-Polytech/FromKotlinToJava
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRecoder.java
More file actions
39 lines (32 loc) · 1.19 KB
/
Copy pathRecoder.java
File metadata and controls
39 lines (32 loc) · 1.19 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
package part2.recode.java;
import java.io.*;
@SuppressWarnings("WeakerAccess")
public class Recoder {
private final String charsetInput;
private final String charsetOutput;
public Recoder(String charsetInput, String charsetOutput) {
this.charsetInput = charsetInput;
this.charsetOutput = charsetOutput;
}
public int recode(InputStream in, OutputStream out) throws IOException {
try (InputStreamReader reader = new InputStreamReader(in, charsetInput)) {
try (OutputStreamWriter writer = new OutputStreamWriter(out, charsetOutput)) {
int sym = reader.read();
int count = 0;
while (sym != -1) {
writer.write(sym);
count++;
sym = reader.read();
}
return count;
}
}
}
public int recode(String inputName, String outputName) throws IOException {
try (FileInputStream inputStream = new FileInputStream(inputName)) {
try (FileOutputStream outputStream = new FileOutputStream(outputName)) {
return recode(inputStream, outputStream);
}
}
}
}