我正在使用scala-arm,我有一个与此类似的代码:
val pathList = List("wrongPath1", "path2", "path3")
val enumerator: Enumerator[Array[Byte]] = Enumerator.outputStream { os =>
managed(new ZipOutputStream(os)).map { zip =>
pathList.map(pdfPath => {
managed(new FileInputStream(pdfPath)).map(new BufferedSource(_)(Codec.ISO8859)).map { inputSrc =>
zip.putNextEntry(new ZipEntry(documentName))
inputSrc map { c: Char => zip.write(c) }
zip.closeEntry()
}.either match {
case Left(errorList) =>
Logger.error("Missing doc")
case Right(_) =>
Logger.error("Doc found")
}
})
}.opt match {
case None => Logger.error("ZIP FAILED")
case Some(_) => Logger.error("ZIP SUCCEED")
}
}
如果托管资源“FileInputStream”或“BufferedSource”失败,则“ZipOutputStream”也会失败,我只在控制台中看到“ZIP FAILED”消息。我从来没有看到“Missing doc”日志。
如果一个路径失败,那么我需要继续将所有其他文件添加到zip文件中。我怎样才能做到这一点?