From 42fa9519c8ceaca589bce3670f143ba350f2cc96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0t=C4=9Bp=C3=A1n=20Brychta?= Date: Tue, 1 Oct 2024 17:33:18 +0100 Subject: [PATCH] Fix failing unarchiver test --- .../bag_unpacker/storage/Unarchiver.scala | 21 ++++++------------- .../fixtures/CompressFixture.scala | 6 +++--- 2 files changed, 9 insertions(+), 18 deletions(-) diff --git a/bag_unpacker/src/main/scala/weco/storage_service/bag_unpacker/storage/Unarchiver.scala b/bag_unpacker/src/main/scala/weco/storage_service/bag_unpacker/storage/Unarchiver.scala index 27d0080876..3759adce85 100644 --- a/bag_unpacker/src/main/scala/weco/storage_service/bag_unpacker/storage/Unarchiver.scala +++ b/bag_unpacker/src/main/scala/weco/storage_service/bag_unpacker/storage/Unarchiver.scala @@ -1,18 +1,9 @@ package weco.storage_service.bag_unpacker.storage -import java.io.{BufferedInputStream, InputStream} -import org.apache.commons.compress.archivers.{ - ArchiveEntry, - ArchiveException, - ArchiveInputStream, - ArchiveStreamFactory -} -import org.apache.commons.compress.compressors.{ - CompressorException, - CompressorInputStream, - CompressorStreamFactory -} +import java.io.{BufferedInputStream, InputStream} +import org.apache.commons.compress.archivers.{ArchiveEntry, ArchiveException, ArchiveInputStream, ArchiveStreamFactory} +import org.apache.commons.compress.compressors.{CompressorException, CompressorInputStream, CompressorStreamFactory} import org.apache.commons.io.input.CloseShieldInputStream import scala.util.{Failure, Success, Try} @@ -51,7 +42,7 @@ object Unarchiver { } yield iterator private def createIterator( - archiveInputStream: ArchiveInputStream + archiveInputStream: ArchiveInputStream[ArchiveEntry] ): Iterator[(ArchiveEntry, InputStream)] = new Iterator[(ArchiveEntry, InputStream)] { private var latest: ArchiveEntry = _ @@ -92,12 +83,12 @@ object Unarchiver { private def extract( inputStream: InputStream - ): Either[UnarchiverError, ArchiveInputStream] = + ): Either[UnarchiverError, ArchiveInputStream[ArchiveEntry]] = Try { // We have to wrap in a BufferedInputStream because this method // only takes InputStreams that support the `mark()` method. new ArchiveStreamFactory() - .createArchiveInputStream(new BufferedInputStream(inputStream)) + .createArchiveInputStream(new BufferedInputStream(inputStream)).asInstanceOf[ArchiveInputStream[ArchiveEntry]] } match { case Success(stream) => Right(stream) case Failure(err: ArchiveException) => Left(ArchiveFormatError(err)) diff --git a/bag_unpacker/src/test/scala/weco/storage_service/bag_unpacker/fixtures/CompressFixture.scala b/bag_unpacker/src/test/scala/weco/storage_service/bag_unpacker/fixtures/CompressFixture.scala index fe83e74ae3..9060d6ba16 100644 --- a/bag_unpacker/src/test/scala/weco/storage_service/bag_unpacker/fixtures/CompressFixture.scala +++ b/bag_unpacker/src/test/scala/weco/storage_service/bag_unpacker/fixtures/CompressFixture.scala @@ -182,7 +182,7 @@ trait CompressFixture[BagLocation <: Location, Namespace] compressorName: String )( outputStream: OutputStream - ): CompressorOutputStream = { + ): CompressorOutputStream[BufferedOutputStream] = { val compressorStreamFactory = new CompressorStreamFactory() @@ -195,13 +195,13 @@ trait CompressFixture[BagLocation <: Location, Namespace] compressorName, bufferedOutputStream ) - } + }.asInstanceOf[CompressorOutputStream[BufferedOutputStream]] private def packer( archiverName: String )( outputStream: OutputStream - ): ArchiveOutputStream = { + ): ArchiveOutputStream[ArchiveEntry] = { val archiveStreamFactory = new ArchiveStreamFactory()