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

org.http4k.routing.experimental.InMemoryResource.kt Maven / Gradle / Ivy

There is a newer version: 5.41.0.0
Show newest version
package org.http4k.routing.experimental

import org.http4k.core.ContentType
import org.http4k.core.etag.ETag
import java.io.ByteArrayInputStream
import java.time.Instant

class InMemoryResource(
    private val content: ByteArray,
    override val contentType: ContentType,
    override val lastModified: Instant? = null,
    override val etag: ETag? = null
) : Resource {

    constructor(
        content: String,
        contentType: ContentType,
        lastModified: Instant? = null,
        etag: ETag? = null
    ) : this(content.toByteArray(Charsets.UTF_8), contentType, lastModified, etag)

    override fun openStream() = ByteArrayInputStream(content)

    override val length: Long? = content.size.toLong()
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy