【发布时间】:2018-02-14 14:29:53
【问题描述】:
type FilePartHandler[A] = FileInfo => Accumulator[ByteString, FilePart[A]]
def handleFilePartAsFile: FilePartHandler[File] = {
case FileInfo(partName, filename, contentType) =>
val perms = java.util.EnumSet.of(OWNER_READ, OWNER_WRITE)
val attr = PosixFilePermissions.asFileAttribute(perms)
val path = Files.createTempFile("multipartBody", "tempFile", attr)
val file = path.toFile
val fileSink = FileIO.toFile(file)
val accumulator = Accumulator(fileSink)
accumulator.map { case IOResult(count, status) =>
FilePart(partName, filename, contentType, file)
}(play.api.libs.concurrent.Execution.defaultContext)
}
我从播放文件上传示例中复制了上述代码。我很难使用typekeyword 的语法。如果我说这样的话
type mytype = Int => String。我可以像下面这样使用它
def method2(f:mytype) = "20"
def f(v:Int) = "hello"
method2(f)
但根据我的理解,我完全不知道在方法 handleFilePartAsFile 中如何使用以下语法,甚至是什么意思?
type FilePartHandler[A] = FileInfo => Accumulator[ByteString, FilePart[A]]
【问题讨论】: