Skip to content

Commit 45d4b20

Browse files
committed
Merge pull request #39 from edeustace/close-streams
close streams
2 parents fe1e869 + e039b3e commit 45d4b20

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

plugin/app/com/ee/assets/transformers/ByteArrayWriter.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ class ByteArrayWriter(fileFn: String => File) extends Transformer[Array[Byte], U
1919
val fileOut = fileFn(e.path)
2020
logger.trace(s"from ${e.path} write bytes to ${fileOut.getPath}")
2121
fileOut.getParentFile.mkdirs()
22-
IOUtils.write(e.contents, new FileOutputStream(fileOut))
22+
val os = new FileOutputStream(fileOut)
23+
IOUtils.write(e.contents, os)
24+
os.close()
2325
PathElement(e.path)
2426
}
2527
}

plugin/app/com/ee/assets/transformers/PlayResourceReader.scala

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,16 @@ class PlayResourceReader extends Transformer[Unit, String] {
2323

2424
val contents = url.map {
2525
u =>
26-
IOUtils.toString(u.openStream())
26+
val stream = u.openStream()
27+
try {
28+
val out = IOUtils.toString(stream)
29+
stream.close()
30+
out
31+
} catch {
32+
case e : Throwable => throw new AssetsLoaderException(s"Error with stream ${u}", e)
33+
} finally{
34+
IOUtils.closeQuietly(stream)
35+
}
2736
}.orElse {
2837
val errorMsg = s"can't load path: ${e.path}"
2938
throw new AssetsLoaderException(errorMsg)

0 commit comments

Comments
 (0)