log data copying

Signed-off-by: Sebastian Schüpbach's avatarSebastian Schüpbach <sebastian.schuepbach@unibas.ch>
parent b08eeef1
Pipeline #18452 passed with stages
in 8 minutes and 7 seconds
......@@ -19,19 +19,20 @@
package ch.memobase
import java.io.{ByteArrayOutputStream, FileOutputStream, IOException}
import java.nio.file.{Files, Path, Paths}
import ch.memobase.models.{Conversions, MimeType}
import org.apache.logging.log4j.scala.Logging
import java.io.{ByteArrayOutputStream, FileOutputStream, IOException}
import java.nio.file.{Files, Path, Paths}
import scala.util.{Failure, Success, Try}
/**
* Manages dissemination copies of media files
*/
class DisseminationCopyHandler(audioSnippetDuration: Int) {
class DisseminationCopyHandler(audioSnippetDuration: Int) extends Logging {
private def writeData(data: ByteArrayOutputStream, destFile: Path): Try[Path] = {
val inSize = data.size
Try(new FileOutputStream(destFile.toFile)) match {
case Success(fos) =>
try {
......@@ -40,6 +41,8 @@ class DisseminationCopyHandler(audioSnippetDuration: Int) {
} catch {
case e: IOException => Failure(e)
} finally {
val outSize = fos.getChannel.size
logger.info(s"$inSize bytes data read, $outSize bytes written for $destFile")
fos.close()
data.close()
}
......@@ -73,7 +76,6 @@ class DisseminationCopyHandler(audioSnippetDuration: Int) {
* @return true if both files were overwritten, false otherwise
*/
def createAudioCopy(data: ByteArrayOutputStream, destFile: String, sourceFileType: MimeType, isSnippet: Boolean = false): Try[Boolean] = Try {
// FIXME
val tempFilePath = Files.createTempFile("media-", "." + Conversions.getFileTypeExtension(sourceFileType).get)
writeData(data, tempFilePath)
val copyRemoved = removeExistingFile(Paths.get(destFile))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment