本文整理汇总了Scala中java.nio.file.StandardCopyOption类的典型用法代码示例。如果您正苦于以下问题:Scala StandardCopyOption类的具体用法?Scala StandardCopyOption怎么用?Scala StandardCopyOption使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了StandardCopyOption类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: Access
//设置package包名称以及导入依赖的类
package hu.blackbelt.cd.bintray.deploy
import java.nio.file.{Files, StandardCopyOption}
import java.util.{Properties, UUID}
import awscala.s3.S3
import com.amazonaws.regions.Regions
import com.amazonaws.services.s3.model.GetObjectRequest
import hu.blackbelt.cd.bintray.VFS.FS
object Access {
val bintray_organization = "bintray.organization"
val bintray_user = "bintray.user"
val bintray_apikey = "bintray.apikey"
val aws_accessKeyId = "aws.accessKeyId"
val aws_secretKey = "aws.secretKey"
def collect = {
implicit val s3 = S3()(com.amazonaws.regions.Region.getRegion(Regions.EU_CENTRAL_1))
val destination = FS.getPath(s"/tmp/${UUID.randomUUID().toString}")
Files.createDirectories(destination)
val s3Object = s3.getObject(new GetObjectRequest("blackbelt-secrets", "bintray-deploy/access.properties"))
Files.copy(s3Object.getObjectContent, destination, StandardCopyOption.REPLACE_EXISTING)
import scala.collection.JavaConverters._
val prop = new Properties()
prop.load(Files.newInputStream(destination))
prop.entrySet().asScala.foreach {
(entry) => {
sys.props += ((entry.getKey.asInstanceOf[String], entry.getValue.asInstanceOf[String]))
}
}
}
}
示例2: Directories
//设置package包名称以及导入依赖的类
import java.net.URI
import java.nio.file.attribute.{FileAttribute, BasicFileAttributes}
import java.nio.file.{StandardCopyOption, Paths, Files, Path}
import io.gatling.core.util.PathHelper._
class Directories(
val data: Path,
val bodies: Path,
val binaries: Path,
val results: Path
)
object IDEPathHelper {
private val uri: URI = getClass.getClassLoader.getResource("gatling.conf").toURI
val directories: Directories = if (uri.getScheme.startsWith("jar")) {
val testDir = System.getProperty("test.dir");
val mainDir: Path = if (testDir != null) {
val dir = Paths.get(testDir);
if (dir.exists) {
if (!dir.isDirectory) {
throw new IllegalArgumentException(testDir + " is not a directory")
}
dir
} else {
Files.createDirectory(dir)
}
} else {
Files.createTempDirectory("gatling-")
}
System.out.println("Using " + mainDir + " as gatling directory")
// unpack gatling.conf
Files.copy(getClass.getResourceAsStream("gatling.conf"), mainDir.resolve("gatling.conf"), StandardCopyOption.REPLACE_EXISTING)
// using createDirectories to ignore existing
val directories = new Directories(
Files.createDirectories(mainDir.resolve("data")),
Files.createDirectories(mainDir.resolve("bodies")),
Files.createDirectories(mainDir.resolve("binaries")),
Files.createDirectories(mainDir.resolve("results")))
val simulationFile: String = Engine.simulationClass.replace('.', '/') + ".class"
// unpack simulation
val targetFile: Path = mainDir.resolve("binaries").resolve(simulationFile)
Files.createDirectories(targetFile.getParent)
Files.copy(getClass.getResourceAsStream(simulationFile), targetFile, StandardCopyOption.REPLACE_EXISTING)
directories
} else {
val projectRootDir = RichPath(uri).ancestor(3)
val mavenResourcesDirectory = projectRootDir / "src" / "test" / "resources"
val mavenTargetDirectory = projectRootDir / "target"
new Directories(
mavenResourcesDirectory / "data",
mavenResourcesDirectory / "bodies",
mavenTargetDirectory / "test-classes",
mavenTargetDirectory / "results")
}
}
示例3: S3
//设置package包名称以及导入依赖的类
package com.sample.lambda
import java.io.File
import java.nio.file.{Files, StandardCopyOption}
import com.amazonaws.services.lambda.runtime.Context
import com.amazonaws.services.lambda.runtime.events.S3Event
import com.amazonaws.services.s3.AmazonS3Client
import com.amazonaws.services.s3.model.{CannedAccessControlList, ObjectMetadata, PutObjectRequest}
import com.typesafe.config.ConfigFactory
import org.im4java.core.{ConvertCmd, IMOperation}
class S3 {
def handler(event: S3Event, context: Context): String = {
val config = ConfigFactory.load()
val record = event.getRecords.get(0)
val bucket = record.getS3.getBucket.getName
val key = record.getS3.getObject.getKey
val pattern = """(.+)\.(.+)""".r
val patternThumbnail = """(.+)_thumbnail\.(.+)""".r
key match {
case patternThumbnail(name, format) => {
}
case pattern(name, format) => {
val client = new AmazonS3Client()
val s3Object = client.getObject(bucket, key)
val inMetadata = s3Object.getObjectMetadata
val input = s3Object.getObjectContent
val inputFile = File.createTempFile("s3handler", "input")
Files.copy(input, inputFile.toPath(), StandardCopyOption.REPLACE_EXISTING)
val resizedImage = File.createTempFile("s3handler", "resizedImage")
val op = new IMOperation()
op.addImage(inputFile.getAbsolutePath)
op.resize(config.getInt("resized.width"), config.getInt("resized.height"))
op.addImage(resizedImage.getAbsolutePath)
val converter = new ConvertCmd()
converter.run(op)
val resizedKey = name + "_thumbnail." + format
val putObjectRequest = new PutObjectRequest(bucket, resizedKey, resizedImage)
val resizedImageMetadata = new ObjectMetadata()
resizedImageMetadata.setContentType(inMetadata.getContentType)
putObjectRequest.withCannedAcl(CannedAccessControlList.PublicRead).withMetadata(resizedImageMetadata)
client.putObject(putObjectRequest)
}
}
key
}
}