本文整理汇总了Scala中java.io.EOFException类的典型用法代码示例。如果您正苦于以下问题:Scala EOFException类的具体用法?Scala EOFException怎么用?Scala EOFException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了EOFException类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Scala代码示例。
示例1: Main
//设置package包名称以及导入依赖的类
package main.scala.com.github.jasimvs.formula1
import java.io.EOFException
object Main {
def main(args: Array[String]) {
// println(RaceConfig.calculateStartingPosition(4633))
// println(RaceConfig.calculateStartingPositionRecursive(4633))
println("Welcome to Formula 1 racer!")
println("Once you enter the track length and number of teams, we will declare the winner! To exit, press enter.")
var flag = true;
while (flag) {
val raceService: RaceService = new DefaultRaceService()
try {
println("Please enter track length (in kms): ")
val trackLength = scala.io.StdIn.readInt()
println(trackLength)
println("Please enter number of teams: ")
val noOfTeams = scala.io.StdIn.readInt()
println(noOfTeams)
if (trackLength > 0 && noOfTeams > 0) {
val race1 = raceService.race(RaceConfig(trackLength, noOfTeams))
printResult(race1)
} else {
//flag = false
println("Only positive numbers are valid.")
}
} catch {
case nfe: NumberFormatException =>
flag = false
case eof: EOFException =>
flag = false
}
}
println("Exiting...")
}
def printResult(raceConfig: RaceConfig) = {
raceConfig.teams.map(team => println(s"Team ${team.teamNumber} # Time: ${team.raceTime} seconds # Final speed: ${team.getCurrentSpeedInKmph} kmph"))
}
}
开发者ID:jasimvs,项目名称:silver-memory,代码行数:45,代码来源:Main.scala
示例2: Repl
//设置package包名称以及导入依赖的类
package org.dsa.iot.ignition
import scala.tools.nsc.interpreter._
import scala.tools.nsc._
import scala.util.Try
import java.io.File
import scala.annotation.tailrec
import java.io.EOFException
object Repl {
val prompt = ""
val settings = buildSettings
val main = new IMain(settings)
def run() = {
main.interpret("import org.dsa.iot.ignition._")
main.interpret("import org.dsa.iot.ignition.core._")
main.interpret("import Main.requester")
main.interpret("import Main.responder")
loop(str => main.interpret(str))
}
def loop(action: (String) => Unit) {
@tailrec def inner() {
Console.print(prompt)
val line = try scala.io.StdIn.readLine catch { case _: EOFException => null }
if (line != null && line != "") {
action(line)
inner()
}
}
inner()
}
private def buildSettings = {
val s = new Settings
s.usejavacp.value = false
s.deprecation.value = true
s.classpath.value += File.pathSeparator + System.getProperty( "java.class.path" )
s
}
}
开发者ID:IOT-DSA,项目名称:dslink-scala-ignition,代码行数:45,代码来源:Repl.scala
示例3: readRecord
//设置package包名称以及导入依赖的类
package org.apache.flink.contrib.tensorflow.io
import java.io.{EOFException, IOException, InputStream}
import org.apache.flink.api.common.io.FileInputFormat
import org.apache.flink.configuration.Configuration
import org.apache.flink.core.fs._
import org.apache.flink.util.Preconditions.checkState
@throws[IOException]
def readRecord(reuse: T, filePath: Path, fileStream: FSDataInputStream, fileLength: Long): T
// --------------------------------------------------------------------------------------------
// Lifecycle
// --------------------------------------------------------------------------------------------
override def nextRecord(reuse: T): T = {
checkState(!reachedEnd())
checkState(currentSplit != null && currentSplit.getStart == 0)
checkState(stream != null)
readRecord(reuse, currentSplit.getPath, stream, currentSplit.getLength)
}
override def reachedEnd(): Boolean = {
stream.getPos != 0
}
}
@SerialVersionUID(1L)
object WholeFileInputFormat {
@throws[IOException]
def readFully(fileStream: FSDataInputStream, fileLength: Long): Array[Byte] = {
if(fileLength > Int.MaxValue) {
throw new IllegalArgumentException("the file is too large to be fully read")
}
val buf = new Array[Byte](fileLength.toInt)
readFully(fileStream, buf, 0, fileLength.toInt)
buf
}
@throws[IOException]
def readFully(inputStream: InputStream, buf: Array[Byte], off: Int, len: Int): Array[Byte] = {
var bytesRead = 0
while (bytesRead < len) {
val read = inputStream.read(buf, off + bytesRead, len - bytesRead)
if (read < 0) throw new EOFException("Premature end of stream")
bytesRead += read
}
buf
}
}
开发者ID:FlinkML,项目名称:flink-tensorflow,代码行数:54,代码来源:WholeFileInputFormat.scala
注:本文中的java.io.EOFException类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论