Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package jetbrains.rsynk.protocol
- import java.io.File
- import java.util.*
- fun main(args: Array<String>) {
- val decoded = decodeLog("/Users/jetbrains/Desktop/log-sender.txt")
- writeDecodedLog(decoded, "log.txt")
- }
- private fun decodeLog(path: String): List<ByteArray> {
- val leftBound = "\n|".toByteArray()
- val rightBound = "|\n".toByteArray()
- val bytes = File(path).readBytes()
- val result = ArrayList<ByteArray>()
- var readPos = 0
- var len = 0
- val buf = ByteArray(bytes.size)
- while (readPos < bytes.size) {
- if (bytes[readPos] == leftBound[0] && bytes[readPos + 1] == leftBound[1]) {
- readPos += 2
- continue
- }
- if (bytes[readPos] == rightBound[0] && bytes[readPos + 1] == rightBound[1]) {
- result += buf.slice(0..len - 1).toByteArray()
- len = 0
- readPos += 2
- continue
- }
- buf[len++] = bytes[readPos++]
- }
- return result
- }
- private fun writeDecodedLog(log: List<ByteArray>, path: String) {
- val file = File(path)
- log.forEach {
- file.appendText(Arrays.toString(it) + "\n")
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement