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

main.wisp.resources.FakeFilesystemLoaderBackend.kt Maven / Gradle / Ivy

There is a newer version: 2024.11.21.163958-33c6589
Show newest version
package wisp.resources

import okio.Buffer
import okio.BufferedSource
import okio.ByteString.Companion.encodeUtf8

/**
 * A fake [FilesystemLoaderBackend] that loads file contents from an in-memory map. The map
 * can be populated by adding to the [ForFakeFiles] map.
 *
 * ```
 * newMapBinder(ForFakeFiles::class).addBinding("/etc/foo.txt").toInstance("hello!")
 * ```
 */
class FakeFilesystemLoaderBackend(
    private val files: Map
) : ResourceLoader.Backend() {
    override fun open(path: String): BufferedSource? {
        val file = files[path] ?: return null
        return Buffer().write(file.encodeUtf8())
    }

    override fun exists(path: String) = files.containsKey(path)
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy