• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Scala ConfigRenderOptions类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Scala DeserializationException类代码示例发布时间:2022-05-23
下一篇:
Scala RenderingHints类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap