Kotlin Converts Bytearray To String Data Crash
Converts bytearray data received through communication into String. If the byte array is long (ex 355), the end is truncated. Same goes for utf-8, utf-16 etc. fun getString(content
Solution 1:
I created a repo that you can run your use-cases against with tests: GitHub
There are several possible issues:
- Can
Log.i
cause any troubles? - Check the initial encoding you encode with:
valstr="My long string"valbyteArray= str.toByteArray(Charset.forName("utf-8"))
- Check the encoding you decode with. In your code, I see that
euc-kr
encoding is hard-coded. It means that if you encoded with utf-8 and decode with a different one, the code will fail.
Post a Comment for "Kotlin Converts Bytearray To String Data Crash"