From cb247c60b5e841ec30ce812d467f92e315067b27 Mon Sep 17 00:00:00 2001 From: John Kasper Svergja Date: Fri, 18 Nov 2022 09:20:19 +0100 Subject: [PATCH] Add overload method for validate which accepts reader Such that a reader of choice can be passed (e.g. a buffered string reader) instead of the whole xml as a string --- src/main/kotlin/no/ssb/kostra/barn/ValidationUtils.kt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/no/ssb/kostra/barn/ValidationUtils.kt b/src/main/kotlin/no/ssb/kostra/barn/ValidationUtils.kt index 074587214..d589a00bc 100644 --- a/src/main/kotlin/no/ssb/kostra/barn/ValidationUtils.kt +++ b/src/main/kotlin/no/ssb/kostra/barn/ValidationUtils.kt @@ -2,6 +2,7 @@ package no.ssb.kostra.barn import org.xml.sax.SAXParseException import java.io.InputStream +import java.io.Reader import java.io.StringReader import javax.xml.XMLConstants import javax.xml.transform.stream.StreamSource @@ -16,8 +17,13 @@ object ValidationUtils { @JvmStatic fun validate(xml: String): Boolean { + return validate(StringReader(xml)) + + } + @JvmStatic + fun validate(xmlReader: Reader): Boolean { return try { - getSchemaValidator().validate(StreamSource(StringReader(xml))) + getSchemaValidator().validate(StreamSource(xmlReader)) true } catch (e: SAXParseException) { false