本文整理汇总了Scala中java.io.PrintWriter类的典型用法代码示例。如果您正苦于以下问题:Scala PrintWriter类的具体用法?Scala PrintWriter怎么用?Scala PrintWriter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PrintWriter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: Main
//设置package包名称以及导入依赖的类
package cdto
import codegen.json._
import codegen.messagetypes._
import compiler._
import datamodel.Protocol
import io.Source
import java.nio.file.Paths
import java.io.{File, PrintWriter}
import codegen.sourcefile.FileDefinition
import org.rogach.scallop._
object Main {
private class ArgConfig(arguments: Seq[String]) extends ScallopConf(arguments) {
val protocol = opt[String](required = true, descr = "Path to the protocol definition file")
val outputDir = opt[String](required = true, descr = "Path to the directory to write the generated files")
val typeHeaders = opt[List[String]](descr = "List of headers containing C-type definitions used in message fields")
verify()
}
def main(args: Array[String]): Unit = {
val parsedArgs = new ArgConfig(args)
val protocolFile = parsedArgs.protocol()
val outputDir = parsedArgs.outputDir()
val typeHeaders = parsedArgs.typeHeaders.getOrElse(Nil)
val protocolName = protocolNameFromPath(protocolFile)
val definition = readProtocolDefinition(parsedArgs.protocol())
val compilerResult = ProtocolCompiler(definition, protocolName)
compilerResult match {
case Left(error) => println(error)
case Right(protocol) => {
writeProtocolTypeFiles(protocol, typeHeaders, outputDir)
writeProtocolJSONFiles(protocol, outputDir)
}
}
}
private def writeFile(outputDir: String, file: FileDefinition): Unit = {
val path = Paths.get(outputDir, file.name)
// TODO: Handle errors
val writer = new PrintWriter(new File(path.toAbsolutePath.toString))
writer.write(file.contents)
writer.close()
}
}
示例2: JavaSource
//设置package包名称以及导入依赖的类
package x7c1.wheat.harvest
import java.io.PrintWriter
import play.twirl.api.TxtFormat
import sbt._
case class JavaSource(
code: String,
file: File
)
class JavaSourceFactory [A <: ResourceParts](
targetDir: File,
className: String,
template: A => TxtFormat.Appendable,
partsFactory: ResourcePartsFactory[A] ){
def createFrom(resource: ParsedResource): JavaSource = {
val parts = partsFactory.createFrom(resource)
JavaSource(
code = template(parts).body,
file = targetDir / s"$className.java"
)
}
}
trait JavaSourcesFactory {
def createFrom(resource: ParsedResource): Seq[JavaSource]
}
object JavaSourceWriter {
def write(source: JavaSource): Unit = {
val parent = source.file.getParentFile
if (!parent.exists()){
parent.mkdirs()
}
val writer = new PrintWriter(source.file)
writer.write(source.code)
writer.close()
}
}
示例3: Exercise05
//设置package包名称以及导入依赖的类
package forimpatient.chapter11
import java.io.PrintWriter
import scala.collection.mutable.ArrayBuffer
object Exercise05 extends App {
println("Chapter 11 Exercise 05")
private val out: PrintWriter = new PrintWriter("src/forimpatient/chapter11/table.html")
private val table: Table = Table() | "Java" | "Scala" || "Gosling" | "Odersky" || "JVM" | "JVM, .NET"
println(table)
out.print(table)
out.close()
class Table {
private val cells = ArrayBuffer("<table>")
def |(str: String) = {
if (cells.size == 1) cells += "<tr>"
cells += "<td>" + str + "</td>"
this
}
def ||(str: String) = {
cells += "</tr><tr>"
cells += "<td>" + str + "</td>"
this
}
override def toString = {
val postfix = if (cells.size > 1) "</tr></table>" else "</table>"
cells.mkString("") + postfix
}
}
object Table {
def apply() = new Table
}
}
示例4: WriterEffectPage
//设置package包名称以及导入依赖的类
package org.atnos.site
package lib
object WriterEffectPage extends UserGuidePage { def is = "Writer".title ^ s2"""
You can then define your own custom `Fold` to log the values to a file:${snippet{
import org.atnos.eff._, all._, syntax.all._
import cats.data.Writer
import java.io.PrintWriter
type S = Fx.fx1[Writer[String, ?]]
val action: Eff[S, Int] = for {
a <- pure[S, Int](1)
_ <- tell("first value "+a)
b <- pure[S, Int](2)
_ <- tell("second value "+b)
} yield a + b
// define a fold to output values
def fileFold(path: String) = new RightFold[String, Unit] {
type S = PrintWriter
val init: S = new PrintWriter(path)
def fold(a: String, s: S): S =
{ s.println(a); s }
def finalize(s: S): Unit =
s.close
}
action.runWriterFold(fileFold("target/log")).run
io.Source.fromFile("target/log").getLines.toList
}.eval}
"""
}
示例5: Result
//设置package包名称以及导入依赖的类
package org.hammerlab.coverage.two_sample.without_intervals
import java.io.PrintWriter
import org.hammerlab.coverage.histogram.JointHistogram
import org.hammerlab.coverage.histogram.JointHistogram.Depth
import org.hammerlab.coverage.two_sample
import org.hammerlab.coverage.two_sample.Count
import org.hammerlab.genomics.reference.NumLoci
case class Result(jh: JointHistogram,
pdf: PDF,
cdf: CDF,
sample1Stats: ReadSetStats,
sample2Stats: ReadSetStats,
totalCoveredLoci: NumLoci,
totalReferenceLoci: NumLoci)
extends two_sample.Result[Count, CSVRow] {
@transient lazy val ReadSetStats(maxDepth1, totalBases1) = sample1Stats
@transient lazy val ReadSetStats(maxDepth2, totalBases2) = sample2Stats
override def toCSVRow(d2c: ((Depth, Depth), Count)): CSVRow =
CSVRow(
d2c,
totalBases1,
totalBases2,
totalCoveredLoci,
totalReferenceLoci
)
override def writeMisc(pw: PrintWriter): Unit = {
pw.println(s"Max depths: $maxDepth1,$maxDepth2")
pw.println(s"Total mapped bases: $totalBases1,$totalBases2")
pw.println(s"Total covered loci: $totalCoveredLoci")
pw.println(s"Total reference loci: $totalReferenceLoci")
}
}
示例6: Result
//设置package包名称以及导入依赖的类
package org.hammerlab.coverage.two_sample.with_intervals
import java.io.PrintWriter
import org.hammerlab.coverage.histogram.JointHistogram
import org.hammerlab.coverage.histogram.JointHistogram.Depth
import org.hammerlab.coverage.one_sample.with_intervals.ReadSetStats
import org.hammerlab.coverage.two_sample
import org.hammerlab.genomics.reference.NumLoci
case class Result(jh: JointHistogram,
pdf: PDF,
cdf: CDF,
sample1Stats: ReadSetStats,
sample2Stats: ReadSetStats,
totalOnLoci: NumLoci,
totalOffLoci: NumLoci)
extends two_sample.Result[Counts, CSVRow] {
@transient lazy val ReadSetStats(maxDepth1, totalBases1, onBases1) = sample1Stats
@transient lazy val ReadSetStats(maxDepth2, totalBases2, onBases2) = sample2Stats
override def toCSVRow(d2c: ((Depth, Depth), Counts)): CSVRow =
CSVRow(
d2c,
totalBases1,
totalBases2,
totalOnLoci,
totalOffLoci
)
override def writeMisc(pw: PrintWriter): Unit = {
pw.println(s"Max depths: $maxDepth1,$maxDepth2")
pw.println(s"Total mapped bases: $totalBases1,$totalBases2")
pw.println(s"Total on-target bases: $onBases1,$onBases2")
pw.println(s"Total on-target loci: $totalOnLoci")
}
}
示例7: WriteLines
//设置package包名称以及导入依赖的类
package org.hammerlab.coverage.utils
import java.io.PrintWriter
import grizzled.slf4j.Logging
import org.hammerlab.paths.Path
object WriteLines
extends Logging {
def apply(path: Path, strs: Iterator[String], force: Boolean): Unit =
if (!force && path.exists) {
logger.info(s"Skipping $path, already exists")
} else {
val os = new PrintWriter(path.outputStream)
strs.foreach(os.println)
os.close()
}
}
示例8: Result
//设置package包名称以及导入依赖的类
package org.hammerlab.coverage.one_sample.without_intervals
import java.io.PrintWriter
import org.hammerlab.coverage.histogram.JointHistogram
import org.hammerlab.coverage.histogram.JointHistogram.Depth
import org.hammerlab.coverage.{ NumBP, one_sample }
import org.hammerlab.coverage.one_sample.without_intervals.ResultBuilder.DC
import org.hammerlab.coverage.one_sample.{ CDF, Count, PDF }
import org.hammerlab.genomics.reference.NumLoci
case class Result(jh: JointHistogram,
pdf: PDF[Count],
cdf: CDF[Count],
maxDepth: Depth,
totalBases: NumBP,
filteredCDF: Array[DC],
totalCoveredLoci: NumLoci,
totalReferenceLoci: NumLoci)
extends one_sample.Result[Count, CSVRow] {
override def toCSVRow(depthCounts: DC): CSVRow = CSVRow(depthCounts, totalBases, totalCoveredLoci, totalReferenceLoci)
override def writeMisc(pw: PrintWriter): Unit = {
pw.println(s"Max depth: $maxDepth")
pw.println(s"Total mapped bases: $totalBases")
pw.println(s"Total covered loci: $totalCoveredLoci")
pw.println(s"Total reference loci: $totalReferenceLoci")
}
}
示例9: Result
//设置package包名称以及导入依赖的类
package org.hammerlab.coverage.one_sample
import java.io.PrintWriter
import java.nio.file.Files
import org.hammerlab.csv._
import org.hammerlab.coverage.Main.getJointHistogramPath
import org.hammerlab.coverage.histogram.JointHistogram
import org.hammerlab.coverage.histogram.JointHistogram.Depth
import org.hammerlab.coverage.utils.{ WriteLines, WriteRDD }
import org.hammerlab.paths.Path
import spire.algebra.Monoid
import scala.reflect.ClassTag
import scala.reflect.runtime.universe.TypeTag
abstract class Result[C: Monoid, CSVRow <: Product : TypeTag : ClassTag]
extends Serializable {
def jh: JointHistogram
def pdf: PDF[C]
def cdf: CDF[C]
def filteredCDF: Array[(Depth, C)]
def toCSVRow(depthCounts: (Depth, C)): CSVRow
def writeMisc(pw: PrintWriter): Unit
def save(dir: Path,
force: Boolean = false,
writeFullDistributions: Boolean = false,
writeJointHistogram: Boolean = false): Unit = {
if (!dir.exists) {
Files.createDirectories(dir)
}
if (writeFullDistributions) {
WriteRDD(dir / "pdf", pdf.map(toCSVRow), force)
WriteRDD(dir / "cdf", cdf.map(toCSVRow), force)
}
if (writeJointHistogram) {
val jhPath = getJointHistogramPath(dir)
if (jhPath.exists) {
jhPath.delete(recursive = true)
}
jh.write(jhPath)
}
WriteLines(dir / "cdf.csv", filteredCDF.map(toCSVRow).toCSV(), force)
val miscPath = dir / "misc"
if (force || !miscPath.exists) {
val pw = new PrintWriter(miscPath.outputStream)
writeMisc(pw)
pw.close()
}
}
}
示例10: getStackTrace
//设置package包名称以及导入依赖的类
package proton.users
import java.io.{PrintWriter, StringWriter}
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter
import java.util.UUID
import spray.json.{JsValue, JsonFormat, _}
trait UsersProtocol {
private def getStackTrace(t: Throwable) = {
val sw: StringWriter = new StringWriter()
val pw: PrintWriter = new PrintWriter(sw)
t.printStackTrace(pw)
sw.toString
}
implicit object ThrowableWriter extends RootJsonWriter[Throwable] {
def write(t: Throwable) = JsObject(
"message" -> JsString(t.getMessage),
"cause" -> t.getCause.toJson,
"stackTrace" -> JsString(getStackTrace(t))
)
}
implicit object MessageFormat extends RootJsonWriter[Message] {
def write(m: Message) = JsObject(
"summary" -> JsString(m.summary),
"errorCode" -> JsNumber(m.errorCode)
)
}
implicit object ValidationFormat extends RootJsonWriter[Validation] {
def write(v: Validation) = {
val fields = Seq[Option[JsField]](
Some("message" -> JsString(v.message)),
Some("errorCode" -> JsNumber(v.errorCode)),
v.exception.map(exception => "exception" -> exception.toJson)
)
JsObject(fields.flatten: _*)
}
}
implicit object UUIDFormat extends JsonFormat[UUID] {
def write(uuid: UUID) = JsString(uuid.toString)
def read(value: JsValue) = value match {
case JsString(uuid) => UUID.fromString(uuid)
case _ => deserializationError("UUID expected.")
}
}
implicit object LocalDateTimeFormat extends JsonFormat[LocalDateTime] {
def write(dateTime: LocalDateTime) = JsString(dateTime.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME))
def read(value: JsValue) = value match {
case JsString(dateTime) => LocalDateTime.parse(dateTime, DateTimeFormatter.ISO_LOCAL_DATE_TIME)
case _ => deserializationError("LocalDateTime expected.")
}
}
}
示例11: writeTo
//设置package包名称以及导入依赖的类
package com.jetprobe.fastgen.common
import java.io.{File, PrintWriter}
import com.typesafe.scalalogging.LazyLogging
def writeTo(f: File): Option[String] = {
val outputPath: Option[String] = if (f.isDirectory) {
Some(f.getAbsolutePath + "/out.json")
} else if (f.exists()) {
logger.warn(s"File : ${f.getName} would be overwritten")
Some(f.getAbsolutePath)
} else
Some(f.getAbsolutePath)
outputPath match {
case Some(path) => {
writeToFile(path, data)
Some(path)
}
case None => {
logger.warn("Unable to write. No valid output specified.")
None
}
}
}
private def using[A <: { def close(): Unit }, B](resource: A)(f: A => B): B =
try f(resource)
finally resource.close()
private def writeToFile(path: String, data: Array[String]): Unit =
using(new PrintWriter(new File(path)))(pw => data.foreach(pw.write))
}
示例12: OutputFile
//设置package包名称以及导入依赖的类
package de.uni_potsdam.hpi.ghc2016
import java.io.PrintWriter
class OutputFile(inputFileName: String) {
val outputFileName = {
val lastIndex = inputFileName.lastIndexOf('.')
inputFileName.substring(0, lastIndex) + ".out"
}
println(outputFileName)
def write(lines: Seq[String]): Unit = {
val pw = new PrintWriter(outputFileName)
lines.foreach { line =>
pw.println(line)
}
pw.close()
}
}
示例13: store
//设置package包名称以及导入依赖的类
package ru.fediq.scrapingkit.backend
import java.io.{BufferedOutputStream, FileOutputStream, PrintWriter}
import ru.fediq.scrapingkit.scraper.ScrapedEntity
import ru.fediq.scrapingkit.util.Utilities
import scala.concurrent.Future
trait FeedExporter extends AutoCloseable {
def store[T <: ScrapedEntity](entity: T): Future[_]
override def close() = {
// Do nothing
}
}
class NoOpFeedExporter extends FeedExporter {
override def store[T <: ScrapedEntity](entity: T) = {
Future.successful()
}
}
class JsonLinesFeedExporter(
path: String
) extends FeedExporter {
val writer = new PrintWriter(new BufferedOutputStream(new FileOutputStream(path, true)))
implicit val dispatcher = Utilities.singleDaemonDispatcher("feed-exporter")
override def store[T <: ScrapedEntity](entity: T) = Future {
writer.println(entity.dump)
}
override def close() = {
writer.close()
}
}
示例14: finalizeGenerator
//设置package包名称以及导入依赖的类
package ppl.delite.framework.extern.codegen.cuda
import scala.virtualization.lms.common._
import scala.virtualization.lms.internal._
import collection.mutable.{ListBuffer}
import collection.mutable.HashMap
import java.io.{FileWriter, BufferedWriter, File, PrintWriter}
import ppl.delite.framework.{Config, DeliteApplication}
import ppl.delite.framework.extern.lib._
import ppl.delite.framework.extern.codegen.GenericGenExternal
import ppl.delite.framework.ops._
import ppl.delite.framework.codegen.delite._
trait CudaGenExternalBase extends GenericGenExternal with CudaGenFat with CudaGenDeliteOps {
val IR: DeliteOpsExp
import IR._
val hdrExt = "h"
lazy val globalInterfaceStream = new PrintWriter(new File(headerDir + "/" + "library" + "." + hdrExt)) // runtime conventions with GPUExecutableGenerator
override def finalizeGenerator() {
globalInterfaceStream.close()
super.finalizeGenerator()
}
/////////////////
// implementation
override def emitHeader(lib: ExternalLibrary) {
// global interface file for all cuda libraries
globalInterfaceStream.println("#include \"" + hdrName(lib) + "." + hdrExt + "\"")
super.emitHeader(lib)
}
def emitMethodCall(sym: Sym[Any], e: DeliteOpExternal[_], lib: ExternalLibrary, args: List[String]) = {
if(isNestedNode) throw new GenerationFailedException(quote(sym) + ": cannot call external libraries within kernels")
val allocInputs = emitMultiLoopAllocFunc(e.allocVal, "alloc_"+quote(sym), "", quote(sym), Map())
val elem = new LoopElem("EXTERN",Map())
elem.funcs += "alloc" -> allocInputs.map(quote)
metaData.outputs.put(sym, elem)
stream.println(e.funcName + "(" + (args mkString ",") + ");")
}
def emitInterfaceAndMethod(lib: ExternalLibrary, funcName: String, args: List[String], global: String, body: String) = {
val funcSignature = "void " + funcName + "(" + (args mkString ",") + ")"
super.emitInterfaceAndMethod(lib, funcName,
funcSignature + ";",
global + "\n" + funcSignature + body
)
}
override def getDataStructureHeaders(): String = {
val out = new StringBuilder
out.append("#include \"library.h\"\n")
super.getDataStructureHeaders() + out.toString
}
}
示例15: CliLogger
//设置package包名称以及导入依赖的类
package org.argus.saf.cli.util
import java.io.{File, FileWriter, PrintWriter}
import java.text.SimpleDateFormat
import java.util.Date
object CliLogger {
def timeStamp: String = new SimpleDateFormat("yyyyMMdd-HHmmss").format(new Date)
def outPrint(s : String) {
scala.Console.out.print(s)
scala.Console.out.flush()
}
def outPrintln(s : String) {
scala.Console.out.println(s)
scala.Console.out.flush()
}
def outPrintln() {
scala.Console.out.println()
scala.Console.out.flush()
}
def errPrintln(s : String) {
scala.Console.err.println(s)
scala.Console.err.flush()
}
def errPrintln() {
scala.Console.err.println()
scala.Console.err.flush()
}
def logError(dir: File, text: String, e: Throwable) {
outPrintln()
errPrintln(text + e.getMessage)
val f = new File(dir, ".errorlog")
f.getParentFile.mkdirs
val fw = new FileWriter(f)
try {
val pw = new PrintWriter(fw)
pw.println("An error occurred on " + timeStamp)
e.printStackTrace(pw)
fw.close()
outPrintln("Written: " + f.getAbsolutePath)
} catch {
case e : Throwable =>
errPrintln("Error: " + e.getMessage)
}
}
}