Advertisement
Guest User

Untitled

a guest
Jun 25th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. package jetbrains.rsynk.protocol
  2.  
  3. import java.io.File
  4. import java.util.*
  5.  
  6. fun main(args: Array<String>) {
  7. val decoded = decodeLog("/Users/jetbrains/Desktop/log-sender.txt")
  8. writeDecodedLog(decoded, "log.txt")
  9.  
  10. }
  11.  
  12. private fun decodeLog(path: String): List<ByteArray> {
  13. val leftBound = "\n|".toByteArray()
  14. val rightBound = "|\n".toByteArray()
  15. val bytes = File(path).readBytes()
  16.  
  17. val result = ArrayList<ByteArray>()
  18. var readPos = 0
  19.  
  20. var len = 0
  21. val buf = ByteArray(bytes.size)
  22.  
  23. while (readPos < bytes.size) {
  24.  
  25. if (bytes[readPos] == leftBound[0] && bytes[readPos + 1] == leftBound[1]) {
  26. readPos += 2
  27. continue
  28. }
  29.  
  30. if (bytes[readPos] == rightBound[0] && bytes[readPos + 1] == rightBound[1]) {
  31. result += buf.slice(0..len - 1).toByteArray()
  32. len = 0
  33. readPos += 2
  34. continue
  35. }
  36.  
  37. buf[len++] = bytes[readPos++]
  38. }
  39. return result
  40. }
  41.  
  42. private fun writeDecodedLog(log: List<ByteArray>, path: String) {
  43. val file = File(path)
  44. log.forEach {
  45. file.appendText(Arrays.toString(it) + "\n")
  46. }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement