当前位置: 首页>>代码示例>>Scala>>正文


Scala ConfigRenderOptions类代码示例

本文整理汇总了Scala中com.typesafe.config.ConfigRenderOptions的典型用法代码示例。如果您正苦于以下问题:Scala ConfigRenderOptions类的具体用法?Scala ConfigRenderOptions怎么用?Scala ConfigRenderOptions使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了ConfigRenderOptions类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。

示例1: CheckpointWriter

//设置package包名称以及导入依赖的类
package com.criteo.dev.cluster.config

import com.typesafe.config.{Config, ConfigFactory, ConfigRenderOptions, ConfigValueFactory}

import collection.JavaConverters._

object CheckpointWriter {
  def apply(checkpoint: Checkpoint): Config = {
    import checkpoint._
    ConfigFactory.empty
      .withValue("created", ConfigValueFactory.fromAnyRef(created.toEpochMilli))
      .withValue("updated", ConfigValueFactory.fromAnyRef(updated.toEpochMilli))
      .withValue("todo", ConfigValueFactory.fromIterable(todo.asJava))
      .withValue("finished", ConfigValueFactory.fromIterable(finished.asJava))
      .withValue("failed", ConfigValueFactory.fromIterable(failed.asJava))
  }

  def render(checkpoint: Checkpoint, configRenderOptions: ConfigRenderOptions = ConfigRenderOptions.concise): String = {
    apply(checkpoint).root.render(configRenderOptions)
  }
} 
开发者ID:criteo,项目名称:berilia,代码行数:22,代码来源:CheckpointWriter.scala

示例2: CheckpointWriterSpec

//设置package包名称以及导入依赖的类
package com.criteo.dev.cluster.config

import java.time.Instant

import com.typesafe.config.ConfigRenderOptions
import org.scalatest.{FlatSpec, Matchers}

class CheckpointWriterSpec extends FlatSpec with Matchers {
  "apply" should "convert a Checkpoint to a Config" in {
    val checkpoint = Checkpoint(
      Instant.ofEpochMilli(1000),
      Instant.ofEpochMilli(2000),
      Set("db.t1"),
      Set("db.t2"),
      Set("db.t3")
    )
    val res = CheckpointWriter(checkpoint).root.render(ConfigRenderOptions.concise)
    res shouldEqual """{"created":1000,"failed":["db.t3"],"finished":["db.t2"],"todo":["db.t1"],"updated":2000}"""
  }
} 
开发者ID:criteo,项目名称:berilia,代码行数:21,代码来源:CheckpointWriterSpec.scala

示例3: CEFParser

//设置package包名称以及导入依赖的类
package io.tazi

import com.typesafe.config.{ConfigFactory, ConfigRenderOptions}

import scala.util.parsing.json._

class CEFParser {

  // Keys are predefined
  val KEYS = List(
    "CEFVersion",
    "DeviceVendor",
    "DeviceProduct",
    "DeviceVersion",
    "SignatureID",
    "Name",
    "Severity"
  )

  def parse(string: String): String ={
    var options = ConfigRenderOptions.defaults()
    options = options.setOriginComments(false)
    options = options.setComments(false)

    val allEntries = scala.collection.mutable.Map[String, String]()
    val tokens = string.split("(?<!\\\\)\\|")

    if (tokens.length < 8) {
      throw new Exception()
    }
    val extension = tokens(7)
    val cefData = this.toConfig(tokens, extension)
    val jsonOut = JSON.parseFull(cefData.root().render(options)).getOrElse(0)

    jsonOut match {
      case map_ : Map[String, String] =>
        allEntries ++= map_
      case _ =>
        throw new Exception()
    }
    JSONObject(allEntries.toMap).toString()
  }

  private def toConfig(tokens: Array[String], extension: String): com.typesafe.config.Config ={
    val regexComma = """\s+(?=([^"]*"[^"]*")*[^"]*$)""".r
    val preConfig = ConfigFactory.parseString("{" + KEYS.zip(tokens).map( x => "\"" + x._1 + "\" : \"" + x._2 + "\"").mkString(", ") + "}")
    ConfigFactory.parseString(regexComma.replaceAllIn(extension, ", ")).withFallback(preConfig)
  }



} 
开发者ID:guemues,项目名称:CEFParser,代码行数:53,代码来源:Parser.scala

示例4: UtilityServiceSlice

//设置package包名称以及导入依赖的类
package com.microworkflow.rest

import akka.http.scaladsl.model.{ContentTypes, HttpEntity, HttpResponse}
import akka.http.scaladsl.server.Route
import akka.http.scaladsl.server.Directives._
import com.typesafe.config.{ConfigFactory, ConfigParseOptions, ConfigRenderOptions, ConfigSyntax}

//noinspection TypeAnnotation
class UtilityServiceSlice {

  val options = ConfigParseOptions.defaults().setSyntax(ConfigSyntax.CONF)
  val intentSchema = ConfigFactory.parseResources("intent-schema.json", options)

  val routes: Route = {
    path("info") {
      get {
        complete(HttpResponse(entity = HttpEntity(ContentTypes.`application/json`, buildinfo.BuildInfo.toJson)))
      }
    } ~ path("intent-schema") {
      pathEnd {
        get {
          complete {
            HttpResponse(entity = HttpEntity(ContentTypes.`application/json`, intentSchema.root().render(ConfigRenderOptions.concise())))
          }
        }
      }
    }
  }
} 
开发者ID:polymorphic,项目名称:shakey,代码行数:30,代码来源:UtilityServiceSlice.scala


注:本文中的com.typesafe.config.ConfigRenderOptions类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。