本文整理汇总了Scala中scala.io.StdIn类的典型用法代码示例。如果您正苦于以下问题:Scala StdIn类的具体用法?Scala StdIn怎么用?Scala StdIn使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了StdIn类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: Demo1
//设置package包名称以及导入依赖的类
package lew.bing.akka.http
import akka.actor.ActorSystem
import akka.http.scaladsl.Http
import akka.http.scaladsl.model._
import akka.http.scaladsl.server.{Directive, RequestContext, Route, RouteResult}
import akka.http.scaladsl.server.Directives._
import akka.stream.ActorMaterializer
import akka.stream.scaladsl.Flow
import scala.io.StdIn
object Demo1 {
def main(args: Array[String]): Unit = {
implicit val system = ActorSystem("my-http")
implicit val materializer = ActorMaterializer()
// needed for the future flatMap/onComplete in the end
implicit val executionContext = system.dispatcher
val route:Route =
path("hello"){
get {
complete(HttpEntity(ContentTypes.`text/html(UTF-8)`,"<h1>Say hello to akka-http</h1>"))
}
}
val map = Flow[RequestContext].map(route)
//???????????
val bindingFuture = Http().bindAndHandle(route,"localhost",9898)
println(s"Server online at http://localhost:9898/\nPress RETURN to stop...")
StdIn.readLine() // let it run until user presses return
bindingFuture
.flatMap(_.unbind()) // trigger unbinding from the port
.onComplete(_ => system.terminate()) // and shutdown when done
}
}
示例2: Main
//设置package包名称以及导入依赖的类
package game_of_life
import game_of_life.controller.GameController
import game_of_life.model.Game
import game_of_life.model.Game.SetupPredicate
import scala.io.StdIn
import scala.reflect.runtime.currentMirror
import scala.tools.reflect.ToolBox
object Main extends App {
val controller = new GameController(
Game(rows = args(0).toInt, columns = args(1).toInt) {
args drop 2 match {
case Array() => Game.randomInit
case Array(word) if word equalsIgnoreCase "blinkers" => (row, column) => row % 4 == 1 && column % 4 < 3
case array => eval[SetupPredicate]("($r: Int, $c: Int) => { " + (array mkString " ") + " }: Boolean")
}
}
)()
do {
controller toggle ()
} while ((StdIn readLine ()) != null)
controller stop ()
private def eval[A](string: String): A = {
val tb = currentMirror mkToolBox ()
val tree = tb parse string
(tb eval tree).asInstanceOf[A]
}
}
示例3: CodebaseAnalyzerAkkaApp
//设置package包名称以及导入依赖的类
package tutor
import akka.actor.{ActorRef, ActorSystem}
import tutor.CodebaseAnalyzeAggregatorActor.AnalyzeDirectory
import scala.io.StdIn
object CodebaseAnalyzerAkkaApp extends App {
val system = ActorSystem("CodebaseAnalyzer")
val codebaseAnalyzerControllerActor: ActorRef = system.actorOf(CodebaseAnalyzerControllerActor.props())
var shouldContinue = true
try {
while (shouldContinue) {
println("please input source file folder or :q to quit")
val input = StdIn.readLine()
if (input == ":q") {
shouldContinue = false
} else {
codebaseAnalyzerControllerActor ! AnalyzeDirectory(input)
}
}
} finally {
println("good bye!")
system.terminate()
}
}
示例4: Boot
//设置package包名称以及导入依赖的类
package com.saleass.app.web
import akka.actor.ActorSystem
import akka.http.scaladsl.Http
import akka.http.scaladsl.model._
import akka.http.scaladsl.server.Directives._
import akka.stream.ActorMaterializer
import scala.io.StdIn
object Boot extends App {
implicit val system = ActorSystem("saleass")
implicit val mat = ActorMaterializer()
implicit val ec = system.dispatcher
val route = path("hello") {
get {
complete(HttpEntity(ContentTypes.`text/html(UTF-8)`, "<h1>Damn you av!"))
}
}
val httpBindFuture = Http().bindAndHandle(route, "localhost", 8080)
StdIn.readLine()
httpBindFuture.flatMap(_.unbind()).onComplete(_ => system.terminate())
}
示例5: WebServer
//设置package包名称以及导入依赖的类
import akka.actor.ActorSystem
import akka.http.scaladsl.Http
import akka.http.scaladsl.model._
import akka.http.scaladsl.server.Directives._
import akka.stream.ActorMaterializer
import scala.io.StdIn
object WebServer {
def main(args: Array[String]) {
implicit val system = ActorSystem("my-system")
implicit val materializer = ActorMaterializer()
implicit val executionContext = system.dispatcher
val route =
path("hello") {
get {
complete(HttpEntity(ContentTypes.`text/html(UTF-8)`, "<h1>Say hello to akka-http</h1>"))
}
}
val bindingFuture = Http().bindAndHandle(route, "0.0.0.0", 8080)
println(s"Server online at http://localhost:8080/\nPress RETURN to stop...")
StdIn.readLine() // let it run until user presses return
bindingFuture
.flatMap(_.unbind()) // trigger unbinding from the port
.onComplete(_ => system.terminate()) // and shutdown when done
}
}
示例6: AService
//设置package包名称以及导入依赖的类
package service.a.app
import scala.concurrent.ExecutionContext
import scala.io.StdIn
import akka.http.scaladsl.Http
import akka.http.scaladsl.marshallers.xml.ScalaXmlSupport.defaultNodeSeqMarshaller
import akka.http.scaladsl.marshalling.ToResponseMarshallable.apply
import akka.http.scaladsl.server.Directive.addByNameNullaryApply
import akka.http.scaladsl.server.Directives._
import akka.http.scaladsl.server.RouteResult.route2HandlerFlow
import akka.stream.ActorMaterializer
import service.a.core.ACoreBooted
object AService extends App with ACoreBooted with AConfig {
protected implicit val executor: ExecutionContext = system.dispatcher
protected implicit val materializer: ActorMaterializer = ActorMaterializer()
val route =
path("hello") {
get {
complete {
<h1>Say hello to akka-http</h1>
}
}
} ~
path("dude") {
get {
complete {
<h1>Say hello to dude</h1>
}
}
}
val bindingFuture = Http().bindAndHandle(route, "localhost", port.toInt)
println(s"Server online at http://localhost:11011/\nPress RETURN to stop...")
StdIn.readLine()
bindingFuture
.flatMap(_.unbind())
.onComplete { _ => system.terminate() }
}
示例7: InterpreterMain
//设置package包名称以及导入依赖的类
package qq
import monix.eval.Task
import monix.execution.CancelableFuture
import monix.execution.Scheduler.Implicits.global
import qq.util.Interpreter
import scala.concurrent.Await
import scala.concurrent.duration._
import scala.io.StdIn
object InterpreterMain extends App {
def runInterpreter(interpreter: Interpreter): Task[Unit] = Task.defer {
println("Entered interpreter " + interpreter.name)
interpreter.resume(StdIn.readLine()).fold(
Task.defer {
val () = println("what?")
runInterpreter(interpreter)
}) {
_.fold(
_ => Task.eval(println("Bye!")),
_.flatMap { case (output, nextInterpreter) =>
val () = println(output)
runInterpreter(nextInterpreter)
}
)
}
}
val interpreterFinished: CancelableFuture[Unit] = runInterpreter(Interpreter.mainMenu).runAsync
val () = Await.result(interpreterFinished, Duration.Inf)
}
示例8: OrderApp
//设置package包名称以及导入依赖的类
package com.github.simonthecat.eventdrivenorders.orderservice
import org.apache.kafka.clients.consumer.KafkaConsumer
import org.apache.kafka.clients.producer.KafkaProducer
import scala.io.StdIn
object OrderApp extends App {
val confirmationService = new ConfirmationService(
confirmationConsumer = new KafkaConsumer[String, String](kafka.storeConfirmationConsumer),
confirmationTopic = "order.confirmation",
replyProducer = new KafkaProducer[String, String](kafka.producerCfg),
replyTopic = "api.reply"
)
val orderService = new OrderProcessingService(
new KafkaConsumer[String, String](kafka.orderConsumerCfg),
"order.order",
new KafkaProducer[String, String](kafka.producerCfg),
"store.update"
)
confirmationService.start()
orderService.start()
StdIn.readLine()
confirmationService.stop()
orderService.stop()
}
示例9: Launcher
//设置package包名称以及导入依赖的类
package org.codeape.sc.backend
import akka.actor.ActorSystem
import akka.http.scaladsl.Http
import akka.http.scaladsl.server.Directives._
import akka.stream.ActorMaterializer
import scala.io.StdIn
object Launcher {
def main(args: Array[String]): Unit = {
implicit val system = ActorSystem("my-system")
implicit val materializer = ActorMaterializer()
// needed for the future flatMap/onComplete in the end
implicit val executionContext = system.dispatcher
val route =
path("") {
getFromFile("backend/target/UdashStatic/WebContent/index.html")
} ~
pathPrefix("scripts"){
getFromDirectory("backend/target/UdashStatic/WebContent/scripts")
} ~
pathPrefix("assets"){
getFromDirectory("backend/target/UdashStatic/WebContent/assets")
}
val bindingFuture = Http().bindAndHandle(route, "localhost", 8080)
println(s"Server online at http://localhost:8080/\nPress RETURN to stop...")
StdIn.readLine() // let it run until user presses return
bindingFuture
.flatMap(_.unbind()) // trigger unbinding from the port
.onComplete(_ => system.terminate()) // and shutdown when done
}
}
示例10: Main
//设置package包名称以及导入依赖的类
package com.bau5.sitetracker.server
import akka.actor.PoisonPill
import akka.util.Timeout
import com.bau5.sitetracker.common.BaseProvider
import com.bau5.sitetracker.common.Events.{Message, MessageAll, SaveRequest}
import scala.concurrent.duration._
import scala.io.StdIn
object Main extends BaseProvider("ServerSystem", "") {
override implicit val timeout: Timeout = Timeout(5 seconds)
val messageAll = "message-all (.+)".r
def main(args: Array[String]) {
val serverActor = newActor[ServerActor]("server")
serverActor ! LoadSavedData
while (true) StdIn.readLine("> ") match {
case "save" =>
serverActor ! SaveRequest
case "quit" =>
serverActor ! SaveRequest
serverActor ! PoisonPill
sys.exit(0)
case messageAll(msg) =>
serverActor ! MessageAll(Message(msg))
case _ =>
println("Unrecognized input.")
}
}
}
示例11: WebServer
//设置package包名称以及导入依赖的类
package dummy_authenticator.server
import akka.actor.ActorSystem
import akka.http.scaladsl._
import akka.stream.ActorMaterializer
import dummy_authenticator.config.Configuration
import dummy_authenticator.rest.Routes
import scala.concurrent.ExecutionContextExecutor
import scala.io.StdIn
object WebServer extends Routes {
val config: Configuration = Configuration.get
implicit val system = ActorSystem(config.app.name)
implicit val materializer = ActorMaterializer()
implicit val ec: ExecutionContextExecutor = system.dispatcher
def main(args: Array[String]) {
val interface = config.server.interface
val port = config.server.dummy_port
// The Magic Words
val bindingFuture = Http().bindAndHandle(routes, interface, port)
// Console "Controls"
println(s"dummy_authenticator online at http://$interface:$port/\nPress RETURN to stop...")
StdIn.readLine() // let it run until user presses return
// Closing Shop
bindingFuture
.flatMap(_.unbind()) // trigger unbinding from the port
.onComplete(_ => system.terminate()) // and shutdown when done
}
}
示例12: WebServer
//设置package包名称以及导入依赖的类
package co.horn.alkes.server
import akka.actor.ActorSystem
import akka.http.scaladsl._
import akka.stream.ActorMaterializer
import co.horn.alkes.auth._
import co.horn.alkes.config.Configuration
import co.horn.alkes.dao.DataHandler
import co.horn.alkes.dao.implementations.riak.RiakDataHandler
import co.horn.alkes.log.Logger
import co.horn.alkes.rest.Routes
import scala.concurrent.ExecutionContextExecutor
import scala.io.StdIn
object WebServer extends Routes {
implicit val system = ActorSystem("alkes")
implicit val materializer = ActorMaterializer()
implicit val ec: ExecutionContextExecutor = system.dispatcher
val config: Configuration = Configuration.get
val dao: DataHandler = new RiakDataHandler(config)
val auth: Authority = new WasatAuthority(config)
val log: Logger = config.log.server
def main(args: Array[String]) {
val interface = config.server.interface
val port = config.server.port
// The Magic Words
val bindingFuture = Http().bindAndHandle(routes, interface, port)
// Console "Controls"
println(s"alkes online at http://$interface:$port/\nPress RETURN to stop...")
StdIn.readLine() // let it run until user presses return
// Closing Shop
bindingFuture
.flatMap(_.unbind()) // trigger unbinding from the port
.onComplete(_ => system.terminate()) // and shutdown when done
}
}
示例13: webServer
//设置package包名称以及导入依赖的类
package akka_in_action.http
import akka.actor.ActorSystem
import akka.stream.ActorMaterializer
import akka.http.scaladsl.Http
import akka.http.scaladsl.model._
import akka.http.scaladsl.server.Directives._
import scala.io.StdIn
object webServer extends App {
implicit val system = ActorSystem("my-system")
implicit val materializer = ActorMaterializer()
implicit val executionContext = system.dispatcher
val route =
path("hello") {
get {
complete(HttpEntity(ContentTypes.`text/html(UTF-8)`, "<h1>Hello, holy crapper.</h2>"))
}
}
val host = "127.0.0.1"
val port = 8080
val bindingFuture = Http().bindAndHandle(route, host, port)
println(s"Server onlien at http://${host}:${port}/\nPress RETURN to stop...")
StdIn.readLine
bindingFuture
.flatMap(_.unbind)
.onComplete(_ => system.terminate)
}
示例14: InventoryApplication
//设置package包名称以及导入依赖的类
package com.tuplejump.inventory.cli
import scala.io.StdIn
import org.jboss.aesh.console._
import org.jboss.aesh.console.settings.SettingsBuilder
import com.tuplejump.inventory.client.Client
object InventoryApplication {
def main(args: Array[String]) {
print("Enter number of POS terminals: ")
val num = StdIn.readInt()
val cli = new Client(num)
cli.start()
val builder: SettingsBuilder = new SettingsBuilder().ansi(true)
builder.logging(true).logfile(System.getProperty("user.dir") +
System.getProperty("file.separator") + "akka.log")
builder.persistHistory(true)
builder.parseOperators(false)
val console: Console = new Console(builder.create)
val consoleCallback: ConsoleCallback = new ConsoleCallBack(console, cli)
console.setConsoleCallback(consoleCallback)
val prompt: Prompt = new Prompt("Enter command>")
console.start()
console.setPrompt(prompt)
}
}
示例15: JavaFXExamples
//设置package包名称以及导入依赖的类
package com.outr.nextui.examples.desktop
import java.util.prefs.Preferences
import com.outr.nextui.desktop.JavaFX
import com.outr.nextui.examples.Examples._
import scala.io.StdIn
object JavaFXExamples {
def main(args: Array[String]): Unit = {
val keyName = "nextui.javafx.examples.lastRun"
val preferences = Preferences.userRoot()
val previousName = preferences.get(keyName, examples.head.name)
val previous = examples.find(_.name == previousName).map(examples.indexOf).getOrElse(0) + 1
println("Choose an example to run:")
examples.zipWithIndex.foreach {
case (example, index) => println(s"\t${index + 1}.) ${example.name}")
}
println(s"Example number 1 - ${examples.size} [$previous]: ")
val i = try {
StdIn.readInt()
} catch {
case t: Throwable => previous
}
val ui = examples(i - 1)
preferences.put(keyName, ui.name)
println(s"Starting ${ui.name}...")
JavaFX(ui)
}
}