forked from Kotlin-Polytech/FromKotlinToJava
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRecoder.kt
More file actions
31 lines (27 loc) · 945 Bytes
/
Copy pathRecoder.kt
File metadata and controls
31 lines (27 loc) · 945 Bytes
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
package part2.recode.kotlin
import java.io.*
class Recoder(private val charsetInput: String, private val charsetOutput: String) {
@Throws(IOException::class)
fun recode(`in`: InputStream, out: OutputStream): Int {
InputStreamReader(`in`, charsetInput).use { reader ->
OutputStreamWriter(out, charsetOutput).use { writer ->
var sym = reader.read()
var count = 0
while (sym != -1) {
writer.write(sym)
count++
sym = reader.read()
}
return count
}
}
}
@Throws(IOException::class)
fun recode(inputName: String, outputName: String): Int {
FileInputStream(inputName).use { inputStream ->
FileOutputStream(outputName).use { outputStream ->
return recode(inputStream, outputStream)
}
}
}
}