当前位置: 首页>>代码示例>>Scala>>正文


Scala Files类代码示例

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


在下文中一共展示了Files类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。

示例1: FileInterpreter

//设置package包名称以及导入依赖的类
package com.dbrsn.datatrain.file

import java.io.File

import cats.~>
import com.dbrsn.datatrain.dsl.FsComponent
import com.dbrsn.datatrain.model.ContentMetadataKey.ContentLengthMetadata
import com.dbrsn.datatrain.model.ContentMetadataKey.ContentMd5Metadata
import com.dbrsn.datatrain.model.MetadataKey
import com.dbrsn.datatrain.model.MetadataValue
import com.dbrsn.datatrain.util.SystemUtil
import com.google.common.io.Files

import scala.util.Try

trait FileComponent
  extends FsComponent {
  import FsDSL._

  type FileFsDSL[A] = FsDSL[A]

  override type FileExisted = File
  override type FileNotExisted = File
  override type DirExisted = File

  val FileMetadataInterpreter: File => PartialFunction[MetadataKey, Try[MetadataValue]] = (file: File) => PartialFunction {
    case ContentLengthMetadata =>
      Try(ContentLengthMetadata(file.length()))
    case ContentMd5Metadata    =>
      Try(ContentMd5Metadata(SystemUtil.base64Md5(file)))
  }

  class FileInterpreter(metadataInterpreter: File => MetadataKey => Try[MetadataValue]) extends (FileFsDSL ~> Try) {
    override def apply[A](fa: FileFsDSL[A]): Try[A] = fa match {
      case CreateTempDir                =>
        Try(Files.createTempDir())
      case Describe(dir, contentName)   =>
        Try(new File(dir, contentName))
      case DeleteFile(file)             =>
        Try {
          file.delete()
          ()
        }
      case DeleteDir(dir)               =>
        Try {
          dir.delete()
          ()
        }
      case ReadMetadata(file, metadata) =>
        metadataInterpreter(file)(metadata)
    }
  }

} 
开发者ID:dborisenko,项目名称:data-train,代码行数:55,代码来源:FileComponent.scala

示例2: CuratorTests

//设置package包名称以及导入依赖的类
package com.bwsw.cloudstack.common.curator

import com.bwsw.cloudstack.imp.dao.zookeeper.ZookeeperTestServer
import com.google.common.io.Files
import org.apache.curator.framework.{CuratorFramework, CuratorFrameworkFactory}
import org.apache.curator.retry.ExponentialBackoffRetry
import org.scalatest.{BeforeAndAfterAll, FlatSpec, Matchers}


class CuratorTests extends FlatSpec with Matchers with BeforeAndAfterAll {
  System.getProperty("java.io.tmpdir", "./target/")
  val ZOOKEEPER_PORT = 21810
  var zk: ZookeeperTestServer = null
  implicit var curator: CuratorFramework = null

  override def beforeAll() = {
    zk = new ZookeeperTestServer(ZOOKEEPER_PORT, Files.createTempDir().toString)
    curator = CuratorFrameworkFactory.builder()
      .retryPolicy(new ExponentialBackoffRetry(1000, 3))
      .namespace("tests")
      .connectString(s"127.0.0.1:$ZOOKEEPER_PORT").build()
    curator.start()
  }

  override def afterAll() = {
    curator.close()
    zk.stop
  }

} 
开发者ID:bwsw,项目名称:cs-imp,代码行数:31,代码来源:CuratorTests.scala

示例3: CompilerTree

//设置package包名称以及导入依赖的类
package org.ucf.spark.ScalaAST
import scala.tools.nsc._
import io._
import scala.io.Source
import scala.reflect.runtime.{universe =>ru}
import scala.tools.reflect.ToolBox
import com.google.common.io.Files
import java.nio.charset.Charset
import java.io.File
import scala.reflect.internal.util.BatchSourceFile


object CompilerTree extends Global(new Settings()){
  new Run
  def parseToTree(path:String) = {
    val code  = AbstractFile.getFile(path)
    val bfs = new BatchSourceFile(code,code.toCharArray)
    val parser = new syntaxAnalyzer.UnitParser(new CompilationUnit(bfs))
    parser.smartParse()
  }
  def parseToString(path:String) = {
      showRaw(this.parseToTree(path))
  }
  def parseWithMirror(path:String) = {
    val source = Files.toString(new File(path),Charset.forName("UTF-8"))
    val toolBox = ru.runtimeMirror(getClass.getClassLoader).mkToolBox()
    toolBox.parse(source)
  }
  
  def parseWithMirrorTypeCheck(path:String) = {
    val source = Files.toString(new File(path),Charset.forName("UTF-8"))
    val toolBox = ru.runtimeMirror(getClass.getClassLoader).mkToolBox()
    toolBox.typecheck(toolBox.parse(source))
  }
  
  
  
} 
开发者ID:bingrao,项目名称:Scala-AST,代码行数:39,代码来源:CompilerTree.scala

示例4: ExampleData

//设置package包名称以及导入依赖的类
package com.kakao.cuesheet.examples.util

import java.io.FileOutputStream

import com.google.common.io.{ByteStreams, Files}

import scala.util.control.NonFatal

object ExampleData {
  lazy val path: String = {
    try {
      val resource = "data.tsv"
      val tmpfile = Files.createTempDir().getAbsolutePath + resource
      val input = getClass.getResourceAsStream(resource)
      val output = new FileOutputStream(tmpfile)
      ByteStreams.copy(input, output)
      input.close()
      output.close()
      tmpfile
    } catch {
      case NonFatal(e) =>
        throw new RuntimeException("Could not copy example data file to temp directory", e)
    }
  }
} 
开发者ID:kakao,项目名称:cuesheet,代码行数:26,代码来源:ExampleData.scala

示例5: Context

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

import java.io.File
import scala.concurrent.duration._
import scala.concurrent.Future

import com.google.common.io.Files
import org.eclipse.jgit.api.Git

private[i18n] final class Context(
    gitUrl: String,
    gitFile: String,
    asyncCache: lila.memo.AsyncCache.Builder,
    keys: I18nKeys
) {

  type Contexts = Map[String, String]

  def get: Fu[Contexts] = cache.get

  private val cache = asyncCache.single[Contexts](
    name = "i18n.contexts",
    fetch,
    expireAfter = _.ExpireAfterWrite(1 hour)
  )

  private def parse(text: String): Contexts =
    text.lines.toList.map(_.trim).filter(_.nonEmpty).map(_.split('=')).foldLeft(Map[String, String]()) {
      case (cs, Array(key, text)) if (keySet contains key) => cs + (key -> text)
      case (cs, Array(key, _)) =>
        // logwarn("i18n context skipped key " + key)
        cs
      case (cs, line) if line startsWith "//" => cs
      case (cs, line) =>
        // logwarn("i18n context skipped line " + line.mkString("="))
        cs
    }

  private lazy val keySet: Set[String] = keys.keys.map(_.en()).toSet

  private def fetch: Fu[Contexts] = gitClone map { dir =>
    val filePath = s"${dir.getAbsolutePath}/$gitFile"
    val content = fileContent(new File(filePath))
    dir.delete
    parse(content)
  }

  private def gitClone: Fu[File] = Future {
    val dir = Files.createTempDir
    dir.deleteOnExit
    Git.cloneRepository
      .setURI(gitUrl)
      .setDirectory(dir)
      .setBare(false)
      .call
    dir
  }

  private def fileContent(file: File) =
    scala.io.Source.fromFile(file.getCanonicalPath, "UTF-8").mkString
} 
开发者ID:DrNixx,项目名称:line,代码行数:62,代码来源:Context.scala

示例6: PlaceDAO

//设置package包名称以及导入依赖的类
package controllers

import javax.inject.Inject

import com.google.common.io.Files
import models.{Place, PlaceData}
import play.api.data.Form
import play.api.data.Forms._
import play.api.libs.Files.TemporaryFile
import play.api.libs.json.Json
import play.api.mvc.Controller
import play.api.mvc.MultipartFormData.FilePart
import play.modules.reactivemongo.json._
import play.modules.reactivemongo.{MongoController, ReactiveMongoApi, ReactiveMongoComponents}
import reactivemongo.api.commands.WriteResult
import reactivemongo.api.{Cursor, ReadPreference}
import reactivemongo.play.json.collection.JSONCollection

import scala.concurrent.{ExecutionContext, Future}

class PlaceDAO @Inject() (val reactiveMongoApi: ReactiveMongoApi)
                         (implicit ec: ExecutionContext)
    extends Controller with MongoController with ReactiveMongoComponents{
  def create(placeData: PlaceData, picture: FilePart[TemporaryFile]): Future[WriteResult] = {
    placesCollection.flatMap(_.insert(Place(placeData.name, placeData.country, placeData.description,
      Files.toByteArray(picture.ref.file))))
  }

  def all(): Future[List[Place]] = placesCollection.flatMap(_.find(Json.obj())
        .cursor[Place](ReadPreference.primaryPreferred).collect[List](Int.MaxValue, Cursor.FailOnError[List[Place]]()))

  def placesCollection: Future[JSONCollection] = database.map(_.collection[JSONCollection]("places"))
}


object PlaceDAO {
  val createPlaceForm = Form(
    mapping(
      "name" -> nonEmptyText,
      "country" -> nonEmptyText,
      "description" -> nonEmptyText
    )(PlaceData.apply)(PlaceData.unapply)
  )
} 
开发者ID:test410,项目名称:picture-gallery,代码行数:45,代码来源:PlaceDAO.scala


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