All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.bjoernpetersen.musicbot.api.loader.FileResource.kt Maven / Gradle / Ivy

There is a newer version: 0.25.0
Show newest version
package net.bjoernpetersen.musicbot.api.loader

import java.io.File
import java.io.IOException
import net.bjoernpetersen.musicbot.spi.loader.Resource

/**
 * A file resource. The file will be deleted when [free] is called.
 *
 * @param file any file
 */
class FileResource(val file: File) : Resource {

    private var deleted = false
    override suspend fun free() {
        deleted = file.delete()
        if (!deleted) throw IOException("Could not delete ${file.path}")
    }

    override val isValid
        get() = !deleted && file.isFile
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy