本文整理汇总了Scala中scala.reflect.io.Path类的典型用法代码示例。如果您正苦于以下问题:Scala Path类的具体用法?Scala Path怎么用?Scala Path使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Path类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Scala代码示例。
示例1: EmbeddedKafka
//设置package包名称以及导入依赖的类
package nl.bigdatarepublic.streaming.embedded.adapter.kafka
import java.util.Properties
import com.typesafe.scalalogging.LazyLogging
import kafka.server.{KafkaConfig, KafkaServerStartable}
import nl.bigdatarepublic.streaming.embedded.entity.EmbeddedService
import scala.collection.JavaConverters._
import scala.reflect.io.Path
import scala.util.{Failure, Success, Try}
class EmbeddedKafka(props: Map[String, String], clearState: Boolean) extends LazyLogging with EmbeddedService {
val kafka: KafkaServerStartable = new KafkaServerStartable(KafkaConfig(props.asJava))
def start(): Unit = {
// Clear out the existing kafka dir upon startup.
if (clearState) {
logger.info("Cleaning Kafka data dir before start...")
kafka.serverConfig.logDirs.foreach { x =>
Try(Path(x).deleteRecursively()) match {
case Success(true) => logger.info("Successfully cleaned Kafka data dir...")
case Success(false) => logger.info("Failed to clean Kafka data dir...")
case Failure(e) => logger.warn("Failed to clean Kafka data dir", e)
}
}
}
logger.info("Starting embedded Kafka...")
kafka.startup()
logger.info("Successfully started embedded Kafka")
}
def stop(): Unit = {
logger.info("Stopping embedded Kafka...")
kafka.shutdown()
logger.info("Successfully stopped embedded Kafka")
}
}
object EmbeddedKafka {
def apply(props: Map[String, String], clearState: Boolean): EmbeddedKafka = new EmbeddedKafka(props, clearState)
def apply(props: Map[String, String]): EmbeddedKafka = new EmbeddedKafka(props, false)
// Java compatibility
def apply(props: Properties, clearState: Boolean): EmbeddedKafka = new EmbeddedKafka(props.asScala.toMap, clearState)
def apply(props: Properties): EmbeddedKafka = new EmbeddedKafka(props.asScala.toMap, false)
}
开发者ID:BigDataRepublic,项目名称:bdr-engineering-stack,代码行数:55,代码来源:EmbeddedKafka.scala
示例2: ReadWriteFileActorSpec
//设置package包名称以及导入依赖的类
package com.mbesida.synchronizer
import java.io.PrintWriter
import akka.actor.{ActorSystem, Props}
import akka.testkit.{ImplicitSender, TestKit}
import au.com.bytecode.opencsv.CSVWriter
import com.mbesida.synchronizer.ReadFileActor.{ReadResult, ReadValue}
import com.mbesida.synchronizer.ReadWriteFileActor.{FailedModification, ModifyFile, SuccessModification}
import org.junit.runner.RunWith
import org.scalatest.junit.JUnitRunner
import org.scalatest.{BeforeAndAfterAll, Matchers, WordSpecLike}
import scala.reflect.io.Path
@RunWith(classOf[JUnitRunner])
class ReadWriteFileActorSpec extends TestKit(ActorSystem("test"))
with ImplicitSender
with Matchers
with WordSpecLike
with BeforeAndAfterAll {
override def beforeAll(): Unit = {
val out = new CSVWriter(new PrintWriter("sampleFile.csv"))
out.writeNext(Array("1.45", "2", "0.45"))
out.close()
}
"ReadWriteFileActor" should {
"modify empty file success scenario" in {
val actor = system.actorOf(Props(classOf[ReadWriteFileActor], "samplef2.csv"))
actor ! ModifyFile(0, 2.4)
expectMsg(SuccessModification)
}
"modify empty file failure scenario" in {
val actor = system.actorOf(Props(classOf[ReadWriteFileActor], "samplef2.csv"))
actor ! ModifyFile(10, 20)
expectMsg(FailedModification)
}
"modify non empty file" in {
val actor = system.actorOf(Props(classOf[ReadWriteFileActor], "sampleFile.csv"))
actor ! ReadValue(2)
expectMsg(ReadResult(Right(0.45)))
actor ! ModifyFile(1, 3.14)
expectMsg(SuccessModification)
actor ! ReadValue(1)
expectMsg(ReadResult(Right(3.14)))
}
}
override def afterAll(): Unit = {
Path("samplef2.csv").deleteIfExists()
Path("sampleFile.csv").deleteIfExists()
}
}
开发者ID:mbesida,项目名称:fileAccessSynchronization,代码行数:59,代码来源:ReadWriteFileActorSpec.scala
示例3: Numpy
//设置package包名称以及导入依赖的类
package testbed
import testbed._
import scala.reflect.io.{File, Path}
import scala.sys.process.{ProcessLogger, Process}
class Numpy[ResultType](val pathToPython: String, numpyImportAlias: String = "np") {
def isInstalled = {
val testPythonCmd = Process(s"$pathToPython --version")
val testNumpyCmd = Process(Seq(pathToPython, "-c", "'import numpy; print(numpy.version)'"))
def pythonInstalled = {
var result = ""
testPythonCmd ! ProcessLogger(line => result += line)
result contains "Python"
}
def numpyInstalled = {
var result = ""
testNumpyCmd ! ProcessLogger(line => result += line)
!(result contains "Error")
}
pythonInstalled && numpyInstalled
}
val NOT_INSTALLED_MSG: String = s"No numpy installation found with $pathToPython."
val PYTHON_SRC_FILE_NAME: String = "src_buffer.py"
def getResult(numpyExpr: String, bufferName: String, resultReader: String => ResultType) = {
assert(isInstalled, NOT_INSTALLED_MSG)
val absolutePathToBuffer = Path(bufferName).toAbsolute.path
val pythonSrcFile = File(PYTHON_SRC_FILE_NAME)
val pythonFileWriteExpr =
s"""import numpy as $numpyImportAlias
|import csv
|with open('$absolutePathToBuffer', 'w') as buffer_file:
| csv_writer = csv.writer(buffer_file, delimiter=',')
| for result_line in $numpyExpr:
| result_line = [result_line]
| csv_writer.writerow(result_line)
""".stripMargin
pythonSrcFile.writeAll(pythonFileWriteExpr)
Process(Seq(pathToPython, pythonSrcFile.toAbsolute.path))!
resultReader(bufferName)
}
}
开发者ID:bethge,项目名称:sketching-testbed,代码行数:56,代码来源:Numpy.scala
注:本文中的scala.reflect.io.Path类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论