Add debug and testing apis to Spinner.

This commit is contained in:
Cody Henthorne
2026-04-21 09:28:01 -04:00
committed by Alex Hart
parent 5d207932c9
commit 8cd92a400c
3 changed files with 438 additions and 21 deletions

View File

@@ -28,6 +28,48 @@ sealed class PluginResult(val type: String) {
val json: String
) : PluginResult("json")
class TsvResult(
private val columns: List<String>,
private val rows: Iterator<List<String?>>
) : PluginResult("tsv") {
fun toInputStream(): InputStream = object : InputStream() {
private var buffer: ByteArray = columns.joinToString("\t").toByteArray()
private var pos: Int = 0
private var done: Boolean = false
override fun read(): Int {
if (!fill()) return -1
return buffer[pos++].toInt() and 0xFF
}
override fun read(b: ByteArray, off: Int, len: Int): Int {
if (!fill()) return -1
val toRead = minOf(buffer.size - pos, len)
System.arraycopy(buffer, pos, b, off, toRead)
pos += toRead
return toRead
}
override fun close() {
(rows as? AutoCloseable)?.close()
}
private fun fill(): Boolean {
while (pos >= buffer.size) {
if (done) return false
if (rows.hasNext()) {
buffer = ("\n" + rows.next().joinToString("\t") { it ?: "" }).toByteArray()
pos = 0
} else {
done = true
return false
}
}
return true
}
}
}
data class ErrorResult(
val status: Response.Status = Response.Status.INTERNAL_ERROR,
val message: String

View File

@@ -286,6 +286,9 @@ internal class SpinnerServer(
is PluginResult.JsonResult -> {
return newFixedLengthResponse(Response.Status.OK, "application/json", pluginResult.json)
}
is PluginResult.TsvResult -> {
return newChunkedResponse(Response.Status.OK, "text/tab-separated-values", pluginResult.toInputStream())
}
is PluginResult.RawFileResult -> {
return newFixedLengthResponse(Response.Status.OK, pluginResult.mimeType, pluginResult.data, pluginResult.length)
}