javax.xml.transform.stream.StreamResult Scala Examples

The following examples show how to use javax.xml.transform.stream.StreamResult. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.
Example 1
Source File: JMeterReporter.scala    From daml   with Apache License 2.0 5 votes vote down vote up
// Copyright (c) 2020 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

package com.daml.ledger.api.perf.util.reporter

import java.io.File

import javax.xml.transform.dom.DOMSource
import javax.xml.transform.stream.StreamResult
import javax.xml.transform.{OutputKeys, TransformerFactory}
import org.scalameter.CurveData
import org.scalameter.api.{Persistor, Reporter, _}
import org.scalameter.utils.Tree
import org.w3c.dom.Document


class JMeterReporter[T: Numeric](clazz: Class[_]) extends Reporter[T] {

  private def writeToFile(document: Document, file: File): Unit = {
    val transformer = TransformerFactory.newInstance.newTransformer
    transformer.setOutputProperty(OutputKeys.INDENT, "yes")
    val source = new DOMSource(document)
    val console = new StreamResult(file)
    transformer.transform(source, console)
  }

  def report(results: Tree[CurveData[T]], persistor: Persistor): Boolean = {

    // resultDir is global setting
    val resultDirLocation = org.scalameter.currentContext(reports.resultDir)
    val resultDir = new File(resultDirLocation, "jmeter")
    resultDir.mkdirs()
    val resultFile = new File(resultDir, s"${clazz.getName.stripSuffix("$")}.xml")

    val document = JMeterXmlGenerator
      .appendToDocument(results, resultFile)

    writeToFile(document, resultFile)

    true
  }

  def report(result: CurveData[T], persistor: Persistor): Unit = ()
} 
Example 2
Source File: ExportModel.scala    From cdsw-simple-serving   with Apache License 2.0 5 votes vote down vote up
package com.cloudera.datascience.cdsw.acme

import java.nio.charset.StandardCharsets
import java.nio.file.StandardOpenOption._
import java.nio.file.{Files, Paths}
import javax.xml.transform.stream.StreamResult

import org.dmg.pmml.Application
import org.jpmml.model.JAXBUtil
import org.jpmml.sparkml.ConverterUtil

import acme.ACMEModel

object ExportModel {
  
  def main(args: Array[String]): Unit = {
    val training = ACMEData.readData()
    val pipeline = ACMEModel.buildModel()
    
    val pmml = ConverterUtil.toPMML(training.schema, pipeline)
    pmml.getHeader.setApplication(new Application("ACME Occupancy Detection"))
    
    val modelPath = Paths.get("src", "main", "resources")
    if (!Files.exists(modelPath)) {
      Files.createDirectory(modelPath)
    }
    val pmmlFile = modelPath.resolve("model.pmml")
    val writer = Files.newBufferedWriter(pmmlFile, StandardCharsets.UTF_8, WRITE, CREATE, TRUNCATE_EXISTING)
    try {
      JAXBUtil.marshalPMML(pmml, new StreamResult(writer))
    } finally {
      writer.close()
    }
  }

}