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

Scala PrintWriter类代码示例

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

本文整理汇总了Scala中java.io.PrintWriter的典型用法代码示例。如果您正苦于以下问题:Scala PrintWriter类的具体用法?Scala PrintWriter怎么用?Scala PrintWriter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了PrintWriter类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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()
  }
} 
开发者ID:gatkin,项目名称:cDTO,代码行数:56,代码来源:Main.scala


示例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()
  }

} 
开发者ID:x7c1,项目名称:Wheat,代码行数:44,代码来源:JavaSource.scala


示例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
  }
} 
开发者ID:Kiryna,项目名称:Scala-for-the-Impatient,代码行数:42,代码来源:Exercise05.scala


示例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}


"""
} 
开发者ID:atnos-org,项目名称:eff,代码行数:40,代码来源:WriterEffectPage.scala


示例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")
  }
} 
开发者ID:hammerlab,项目名称:coverage-depth,代码行数:39,代码来源:Result.scala


示例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")
  }
} 
开发者ID:hammerlab,项目名称:coverage-depth,代码行数:40,代码来源:Result.scala


示例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()
    }
} 
开发者ID:hammerlab,项目名称:coverage-depth,代码行数:19,代码来源:WriteLines.scala


示例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")
  }
} 
开发者ID:hammerlab,项目名称:coverage-depth,代码行数:32,代码来源:Result.scala


示例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()
    }
  }
} 
开发者ID:hammerlab,项目名称:coverage-depth,代码行数:62,代码来源:Result.scala


示例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.")
    }
  }
} 
开发者ID:Morgan-Stanley,项目名称:proton,代码行数:60,代码来源:UsersProtocol.scala


示例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))
} 
开发者ID:amezng,项目名称:fastgen,代码行数:37,代码来源:FileWriter.scala


示例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()
	}

} 
开发者ID:knub,项目名称:google-hash-code-2016,代码行数:22,代码来源:OutputFile.scala


示例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()
  }
} 
开发者ID:fediq,项目名称:scraping-kit,代码行数:39,代码来源:FeedExporter.scala


示例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
  }
     
} 
开发者ID:leratojeffrey,项目名称:OptiSDR-Compiler,代码行数:60,代码来源:CudaGenExternalBase.scala


示例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)
    }
  }
} 
开发者ID:arguslab,项目名称:Argus-SAF,代码行数:55,代码来源:CliLogger.scala


示例16: maybeGraph

//设置package包名称以及导入依赖的类
package neuroflow.core

import java.io.{File, FileOutputStream, PrintWriter}

import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.Future
import scala.util.Try


  def maybeGraph(error: Double): Unit =
    self.settings.errorFuncOutput.foreach {
      efo =>
        Future {
          Try {
            val handleOpt = efo.file
              .map(f => new PrintWriter(new FileOutputStream(new File(f), true)))
            handleOpt.foreach(_.println(error))
            handleOpt.foreach(_.close())
            efo.closure.foreach(_ (error))
          }
        }
    }

}

case class ErrorFuncOutput(file: Option[String] = None, closure: Option[Double => Unit] = None) 
开发者ID:zenecture,项目名称:neuroflow,代码行数:27,代码来源:ErrorFuncGrapher.scala


示例17: MainRank

//设置package包名称以及导入依赖的类
import GraphReader._
import PageRank._
import java.io
import java.io.PrintWriter

import collection.parallel.ParSeq;

object MainRank {
  def main(args: Array[String]) {
    val graph = readEdges("/Email-Enron.txt")
    val parGraph: ParSeq[(Int,Int)] = graph.par
    // get all nodes
    val nodeId: ParSeq[Int] = parGraph.map{_._1}.toSet.union(parGraph.map{_._2}.toSet).toSeq
    val startRank: ParSeq[Float] = nodeId.map{x=>1.0f/nodeId.size}
    val damp = 0.8f
    val endRank = compRank(startRank,graph,0.4f,0.001f)
    // nodeId.zip(endRank).foreach(tup=>println(tup._1 + " " + tup._2))
    lazy val result: String = nodeId.zip(endRank).map(tup=>(tup._1 + " " + tup._2)).mkString("\n")
    new PrintWriter("resultRank") { write(result); close}
  }

  def toInt(s: String): Option[Int] = {
    try {
      Some(s.toInt)
    } catch {
      case e: Exception => None
    }
  }

} 
开发者ID:mbesancon,项目名称:PageRank,代码行数:31,代码来源:MainRank.scala


示例18: CSPHelpFormatterTest

//设置package包名称以及导入依赖的类
package com.github.madoc.create_sbt_project.cli

import java.io.PrintWriter

import com.github.madoc.create_sbt_project.io.Write.WriteToAppendable
import org.scalatest.{FreeSpec, Matchers}

class CSPHelpFormatterTest extends FreeSpec with Matchers {
  "directory is only attached to the usage line" in {
    val formatter = new CSPHelpFormatter
    val (sb1, sb2) = (new java.lang.StringBuilder, new java.lang.StringBuilder)
    formatter.printWrapped(new PrintWriter(new WriteToAppendable(sb1) asJavaIOWriter), 100, 2, "usage: a b c")
    formatter.printWrapped(new PrintWriter(new WriteToAppendable(sb2) asJavaIOWriter), 100, 2, "non-usage: a b c")
    sb1.toString.trim should be ("usage: a b c [directory]")
    sb2.toString.trim should be ("non-usage: a b c")
  }
} 
开发者ID:Madoc,项目名称:create-sbt-project,代码行数:18,代码来源:CSPHelpFormatterTest.scala


示例19: LogAnalyzerExportSmallData

//设置package包名称以及导入依赖的类
package com.databricks.apps.logs.chapter3

import java.io.{BufferedWriter, FileWriter, PrintWriter}

import org.apache.spark.rdd.RDD
import org.apache.spark.sql.SparkSession

import com.databricks.apps.logs.{ApacheAccessLog, LogAnalyzerRDD}

/**
  * LogAnalyzerExportSmallData shows how to export data of small size to a file.
  *
  * Example command to run:
  * %  ${YOUR_SPARK_HOME}/bin/spark-submit
  * --class "com.databricks.apps.logs.chapter3.LogAnalyzerExportSmallData"
  * --master spark://YOUR_SPARK_MASTER
  * target/scala-2.11/spark-logs-analyzer_2.11-2.0.jar
  * ../../data/apache.access.log output.log
  */
object LogAnalyzerExportSmallData extends App {
  // Initialize SparkSession instance.
  val spark = SparkSession
    .builder()
    .appName("Log Analyzer SQL in Scala")
    .getOrCreate()

  val logFile = args(0)

  val accessLogs: RDD[ApacheAccessLog] = spark
    .sparkContext
    .textFile(logFile)
    .map(ApacheAccessLog.parseLogLine)

  val logAnalyzerRDD = LogAnalyzerRDD(spark)
  val logStatistics = logAnalyzerRDD.processRdd(accessLogs)

  val outputFile = args(1)

  val out = new PrintWriter(new BufferedWriter(new FileWriter(outputFile)))
  val contentSizeStats = logStatistics.contentSizeStats
  out.println("Content Size Avg: %s, Min: %s, Max: %s"
    .format(contentSizeStats._1 / contentSizeStats._2,
      contentSizeStats._3,
      contentSizeStats._4))
  out.println(s"""Response code counts: ${logStatistics.responseCodeToCount.mkString("[", ",", "]")}""")
  out.println(s"""IPAddresses > 10 times: ${logStatistics.ipAddresses.mkString("[", ",", "]")}""")
  out.println(s"""Top Endpoints: ${logStatistics.topEndpoints.mkString("[", ",", "]")}""")
  out.close()

  spark.stop()
} 
开发者ID:krish121,项目名称:Spark-reference-applications,代码行数:52,代码来源:LogAnalyzerExportSmallData.scala


示例20:

//设置package包名称以及导入依赖的类
package org.GutenburgNLP

import java.io.PrintWriter

import com.typesafe.config.{Config, ConfigFactory}
import org.GutenburgNLP.utils.JSONUtility.getAsMap
import org.GutenburgNLP.utils.TimingUtility.timing

import scala.collection.parallel.ParSeq


  val conf: Config = ConfigFactory.load()
  val jsonPath: String = conf.getString("TOP_LEVEL_DIR") + conf.getString(
    "PYTHON_JSON")

  timing {

    // Load the JSON Data into Environment
    val jsonData: ParSeq[List[String]] = getAsMap(jsonPath)
      .map { case (k, v) => (k, v.subjects) }
      .filter { case (k, v) => v.isDefined }
      .filterNot { case (k, v) => v.head.isEmpty }
      .map { case (k, v) => (k, v.head) }
      .values
      .toSeq

    val topSubject: Map[String, Int] = jsonData.flatten
      .foldLeft(Map.empty[String, Int]){
        (count, word) => count + (word -> (count.getOrElse(word, 0) + 1))
      }

    // Find the X most frequent subjects
    val sortTopSubjects = topSubject.toList
      .sortWith(_._2 > _._2)
      .zipWithIndex

    // Print Top 10 to File
    sortTopSubjects
      .foreach {
        case (x, y) => println(s"Rank: ${y + 1} => Subject: ${x._1} Count: ${x._2}")
      }

    // Save the Data to the Resources directory
    val resultsPath = conf.getString("TOP_LEVEL_DIR") + conf.getString(
      "TOP_SUBJECTS")
    new PrintWriter(resultsPath) {
      sortTopSubjects.foreach {
        case (k, v) =>
          write(k._1 + "," + k._2)
          write("\n")
      }
      close()
    }

  }

  println(s"End Date and time: ${java.time.LocalDateTime.now}")
} 
开发者ID:dandxy89,项目名称:SparkScalaGutenburgNLP,代码行数:59,代码来源:A02ExtractingMetaData.scala



注:本文中的java.io.PrintWriter类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Scala NonFatal类代码示例发布时间:2022-05-23
下一篇:
Scala FileInputStream类代码示例发布时间: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