Move closing the InputStream
into an onDoneEnumerating
block, and use Enumerator.fromStream
instead of Enumerator.outputStream
:
val s3Object = s3Client.getObject(new GetObjectRequest(bucket, path))
val in = s3Object.getObjectContent()
val enumerator = Enumerator.fromStream(in).onDoneEnumerating {
in.close()
}
fromStream
reads chunks (8 KiB by default) at a time, so a BufferedInputStream
is unnecessary.
Also, with outputStream
, there is no way for the Iteratee
to push back if it is slow to consume the data, which could result in a large amount of data (up to the size of the S3 object) buffering in memory. This is dangerous, because the application could run out of memory. With fromStream
, the next read won't occur until the Iteratee
is ready for more data.