Comment convertir la taille des octets en format lisible par humain en Java

fun bytesIntoHumanReadable(bytes: Long): String {
            val kilobyte: Long = 1024
            val megabyte = kilobyte * 1024
            val gigabyte = megabyte * 1024
            val terabyte = gigabyte * 1024
            return if (bytes >= 0 && bytes < kilobyte) {
                "$bytes B"
            } else if (bytes >= kilobyte && bytes < megabyte) {
                (bytes / kilobyte).toString() + " KB"
            } else if (bytes >= megabyte && bytes < gigabyte) {
                (bytes / megabyte).toString() + " MB"
            } else if (bytes >= gigabyte && bytes < terabyte) {
                (bytes / gigabyte).toString() + " GB"
            } else if (bytes >= terabyte) {
                (bytes / terabyte).toString() + " TB"
            } else {
                "$bytes Bytes"
            }
        }
android developer