view antlib/Du.kt @ 30:098c4f5507c7

Convert to JDK 15.
author David Barts <n5jrn@me.com>
date Mon, 13 Jun 2022 11:31:49 -0700
parents e90d290a9a8d
children
line wrap: on
line source

import java.io.File
import java.io.IOException

class Du : org.apache.tools.ant.Task() {
    var path: String? = null
    var output: String? = null

    override fun execute(): Unit {
        project.setProperty(output, du(path!!).toString())
    }

    private fun du(path: String): Long {
        try {
            return File(path).walk().map { if (it.isFile()) { it.length() } else { 0L } }.sum()
        } catch (e: IOException) {
            return 0L
        }
    }
}