com.github.mmauro94.mkvtoolnix_wrapper.json.DimensionConverter.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mkvtoolnix-wrapper Show documentation
Show all versions of mkvtoolnix-wrapper Show documentation
An easy to use light kotlin-jvm wrapper for most common mkvmerge and mkvpropedit CLI commands
The newest version!
package com.github.mmauro94.mkvtoolnix_wrapper.json
import com.beust.klaxon.Converter
import com.beust.klaxon.JsonValue
import com.beust.klaxon.KlaxonException
import java.awt.Dimension
internal object DimensionConverter : Converter {
override fun canConvert(cls: Class<*>) = cls == Dimension::class.java
override fun fromJson(jv: JsonValue) = jv.string?.let {
it.split("x").let { tokens ->
Dimension(tokens[0].toInt(), tokens[1].toInt())
}
}
override fun toJson(value: Any): String {
return if (value is Dimension) "\"" + value.width + "x" + value.height + "\""
else throw KlaxonException("Must be Dimension")
}
}