I'm using scala-arm and I have a code similar to this one:
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")
}
}
If managed resources "FileInputStream" or "BufferedSource" fail, then the "ZipOutputStream" also fails and I only see "ZIP FAILED" message in the console. I never see the "Missing doc" log.
If one path fails, then I need to continue adding all other files to the zip file. How can I achieve that?