Я хотел бы получить что-то вроде этого:
...2 47 ef bf bd cb 92 3a 53 0e 5e ef bf bd ef bf bd d6...
Как я понял, это строковое содержимое файла, которое преобразуется в байты. Я пробовал таким образом:
override fun onActivityResult(requestCode: Int, resultCode: Int, result: Intent?) {
super.onActivityResult(requestCode, resultCode, result)
when {
requestCode == 1 && resultCode == Activity.RESULT_OK -> {
if (result != null) {
val documentFile: DocumentFile = DocumentFile.fromSingleUri(this, result.data!!)!!
val hereUrl: Uri? = result.data
val inputStream = this.contentResolver.openInputStream(hereUrl!!)
val byteArray = inputStream!!.readBytes().contentToString()
Timber.i(byteArray.toUtf8Bytes().toString())
}
}
}
}
Но в результате я получаю такой вывод при logcat:
[B@70da221
Итак, как получить такие пары цифр и букв?
ОБНОВЛЕНИЕ
Я создал такую функцию:
fun byteToHex(num: ByteArray): ArrayList<String> {
val stringArray = ArrayList<String>()
for (i in num.indices){
val hexDigits = CharArray(2)
hexDigits[0] = Character.forDigit(i shl 4 and 0xF, 16)
hexDigits[1] = Character.forDigit(i and 0xF, 16)
stringArray.add(String(hexDigits))
}
return stringArray
}
и получаю такой вывод:
00, 01, 02, 03, 04, 05, 06, 07, 08, 09, 0a, 0b, 0c, 0d, 0e, 0f, 00, 01, 02, 03, 04, 05, 06, 07, 08, 09, 0a, 0b, 0c, 0d, 0e, 0f, 00, 01, 02, 03, 04, 05, 06, 07, 08, 09, 0a, 0b, 0c, 0d, 0e, 0f, 00, 01, 02, 03, 04, 05, 06, 07, 08, 09, 0a, 0b, 0c, 0d, 0e, 0f, 00, 01, 02, 03, 04, 05, 06, 07, 08, 09, 0a, 0b, 0c, 0d, 0e, 0f, 00, 01, 02, 03, 04, 05, 06, 07, 08, 09, 0a, 0b, 0c, 0d, 0e, 0f, 00, 01, 02, 03, 04, 05, 06, 07, 08, 09, 0a, 0b, 0c, 0d, 0e, 0f, 00, 01, 02, 03, 04, 05, 06, 07, 08, 09, 0a, 0b, 0c, 0d, 0e, 0f, 00, 01, 02, 03, 04, 05, 06, 07, 08, 09, 0a, 0b, 0c, 0d, 0e, 0f, 00, 01, 02, 03, 04, 05, 06, 07, 08, 09, 0a, 0b, 0c, 0d, 0e, 0f, 00, 01, 02, 03, 04, 05, 06, 07, 08, 09, 0a, 0b, 0c, 0d, 0e, 0f, 00, 01, 02, 03, 04, 05, 06, 07, 08, 09, 0a, 0b, 0c, 0d, 0e, 0f, 00, 01, 02, 03, 04, 05, 06, 07, 08, 09, 0a, 0b, 0c, 0d, 0e, 0f, 00, 01, 02, 03, 04, 05, 06, 07, 08, 09, 0a, 0b, 0c, 0d, 0e, 0f, 00,
но, как я вижу, что-то идет не так: (