本文整理汇总了Scala中java.io.FileFilter类的典型用法代码示例。如果您正苦于以下问题:Scala FileFilter类的具体用法?Scala FileFilter怎么用?Scala FileFilter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FileFilter类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Scala代码示例。
示例1: Configuration
//设置package包名称以及导入依赖的类
package pi.jenkins.build
import java.io.{File, FileFilter}
import com.typesafe.config.{Config, ConfigFactory}
import org.slf4j.LoggerFactory
object Configuration {
private val LOG = LoggerFactory.getLogger(getClass)
private[this] def configDir =
sys.props.get("JENKINS_CONFIG_HOME").map {
fname ? new File(fname)
} getOrElse {
val home = sys.env("HOME")
new File(new File(home), ".jenkins-pi")
}
private lazy val cfg: Config = {
val c = {
val dir = configDir
LOG.trace("Reading files from {}", configDir)
if (dir.exists()) {
dir.listFiles(new FileFilter {
override def accept(pathname: File): Boolean =
pathname.getName.endsWith(".conf") || pathname.getName.endsWith(".properties")
}).foldLeft(ConfigFactory.empty()) {
case (lc, src) ?
LOG.trace("Loading configuration from '{}'", src)
lc.withFallback(ConfigFactory.parseFile(src))
}
} else {
ConfigFactory.empty()
}
}.withFallback(ConfigFactory.load("jenkins_config"))
.withFallback(ConfigFactory.load("jenkins_config_reference"))
.withFallback(ConfigFactory.load())
LOG.trace(s"Config rendered as ${c.root().render()}")
c
}
object Api {
lazy val Username = cfg.getString("pi.jenkins.api.username")
lazy val AccessKey = cfg.getString("pi.jenkins.api.accesskey")
}
}
开发者ID:jdevelop,项目名称:rpi-jenkins,代码行数:55,代码来源:Configuration.scala
示例2: FileTools
//设置package包名称以及导入依赖的类
package geotrellis.migration.core.backend
import geotrellis.migration.core.AttributeStoreTools
import geotrellis.spark._
import geotrellis.spark.io.file.{FileAttributeStore, FileLayerHeader}
import geotrellis.spark.io.file.FileAttributeStore._
import org.apache.commons.io.filefilter.WildcardFileFilter
import spray.json._
import java.io.FileFilter
import geotrellis.migration.cli.{FileArgs, TransformArgs}
class FileTools(val attributeStore: FileAttributeStore) extends AttributeStoreTools {
val format = "file"
lazy val layerIds = attributeStore.layerIds
def readAll[T: JsonFormat](layerId: Option[LayerId], attributeName: Option[String]): List[(Option[LayerId], T)] = {
val filter: FileFilter = (layerId, attributeName) match {
case (Some(id), None) => new WildcardFileFilter(s"${id.name}${SEP}${id.zoom}${SEP}*.json")
case (None, Some(attr)) => new WildcardFileFilter(s"*${SEP}${attr}.json")
case (Some(id), Some(attr)) => new WildcardFileFilter(s"${id.name}${SEP}${id.zoom}${SEP}${attr}.json")
case _ => new WildcardFileFilter("*.json")
}
attributeStore.attributeDirectory
.listFiles(filter)
.map(attributeStore.read[T])
.map { case (id, v) => Some(id) -> v }
.toList
}
def layerMove(layerName: String, args: TransformArgs): Unit = genericLayerMove[FileLayerHeader](layerName, args)
}
object FileTools {
def apply(args: FileArgs) = new FileTools(new FileAttributeStore(args.rootPath))
}
开发者ID:lossyrob,项目名称:geotrellis-migration-tool,代码行数:38,代码来源:FileTools.scala
示例3: DirectoryTreeController
//设置package包名称以及导入依赖的类
package controllers
import java.io.{FileFilter, File}
import java.nio.file.{Paths, Path, Files}
import javax.inject._
import play.api.libs.json._
import play.api.mvc._
import scala.concurrent.ExecutionContext
@Singleton
class DirectoryTreeController @Inject()()(implicit exec: ExecutionContext) extends Controller {
implicit val fileAsNode = new Writes[File] {
def writes(file: File) = {
Json.obj (
"path" -> file.getAbsolutePath,
"name" -> file.getName,
"isDirectory" -> file.isDirectory
)
}
}
private val fileFilter = new FileFilter {
def accept(pathname: File): Boolean = {
(!pathname.isHidden) && pathname.canRead
}
}
def getDirectory(directoryOpt: Option[String]) = Action {
val directory = {
val directoryOrHash = directoryOpt.getOrElse("#")
if (directoryOrHash == "#")
"/"
else
directoryOrHash
}
val path = Paths.get(directory)
if (!Files.isDirectory(path)) {
NotFound(s"$directory is not a valid directory")
} else {
Ok(
Json.obj (
"path" -> path.toFile.getAbsolutePath,
"items" -> Json.toJson(path.toFile.listFiles(fileFilter))
)
)
}
}
}
开发者ID:pequalsnp,项目名称:portroyal,代码行数:51,代码来源:DirectoryTreeController.scala
示例4: explodeClasspath
//设置package包名称以及导入依赖的类
package com.hindog.grid
import java.io.{File, FileFilter}
import java.net.{JarURLConnection, URL, URLDecoder}
import scala.collection.JavaConverters._
import scala.collection._
def explodeClasspath(classpath: String = System.getProperty("java.class.path")): Array[URL] = {
classpath.split(File.pathSeparator).flatMap(file => {
if (file.endsWith(".jar")) {
try {
val url = new URL("jar:file:" + file + "!/META-INF/MANIFEST.MF")
val jarConnection = url.openConnection().asInstanceOf[JarURLConnection]
val manifest = new java.util.jar.Manifest(jarConnection.getInputStream)
manifest.getMainAttributes.getValue("Class-Path").split("\\s+").map(f => URLDecoder.decode(f, "UTF-8")).toSeq
} catch {
case ex: Exception => Seq(file)
}
} else if (file.endsWith("*")) {
new File(file.stripSuffix("*")).listFiles(new FileFilter {
override def accept(pathname: File): Boolean = pathname.getName.endsWith(".jar") || pathname.getName.endsWith(".xml") || pathname.getName.endsWith(".properties") || pathname.getName.endsWith(".class")
}).map(_.toString).toSeq
} else {
Seq(file)
}
}).map(s => new File(s).toURI.toURL)
}
}
开发者ID:hindog,项目名称:grid-executor,代码行数:31,代码来源:ClasspathUtils.scala
示例5: DefaultPdf2PngConverterTests
//设置package包名称以及导入依赖的类
import java.io.{File, FileFilter}
import com.cascomio.tesseract.example.{Config, DefaultPdf2PngConverter}
import org.scalatest.{BeforeAndAfterAll, Matchers, WordSpecLike}
class DefaultPdf2PngConverterTests extends WordSpecLike
with BeforeAndAfterAll
with Matchers {
"A pdf to png converter" should {
"convert the provided file to png" in {
val converter = new DefaultPdf2PngConverter
val filePath = getClass.getResource("/menu.pdf").getPath
val parentFilePath = new File(filePath).getParent
val config = new Config(filePath, filePath)
converter.convert(config)
val createdFiles = new File(parentFilePath).listFiles(new FileFilter {
override def accept(path: File): Boolean = {
val pathname = path.getAbsolutePath
pathname.startsWith(config.filePath) &&
pathname.toLowerCase().endsWith("png")
}
})
assert(createdFiles.size > 0, "No png files created")
}
}
}
开发者ID:Painyjames,项目名称:tesseract-example,代码行数:29,代码来源:DefaultPdf2PngConverterTests.scala
注:本文中的java.io.FileFilter类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论