Skip to content

Commit

Permalink
Merge pull request #1395 from rochala/fix-unoptimal-api-usage
Browse files Browse the repository at this point in the history
Copy bytes directly instead of using `scala.reflect.io.Streamable`
  • Loading branch information
eed3si9n committed Sep 11, 2024
2 parents 574dd92 + ed57d0e commit 5a7012f
Showing 1 changed file with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
package xsbt

import xsbti.{ PathBasedFile, VirtualFile }
import scala.reflect.io.Streamable

private trait AbstractZincFile extends scala.reflect.io.AbstractFile {
def underlying: VirtualFile
Expand All @@ -25,7 +24,22 @@ private final class ZincPlainFile private[xsbt] (val underlying: PathBasedFile)
private final class ZincVirtualFile private[xsbt] (val underlying: VirtualFile)
extends scala.reflect.io.VirtualFile(underlying.name, underlying.id)
with AbstractZincFile {
Streamable.closing(output)(_.write(Streamable.bytes(underlying.input))) // fill in the content
val buffer = new Array[Byte](4096)

val in = underlying.input()
val output0 = output

try {
var readBytes = in.read(buffer)

while (readBytes != -1) {
output0.write(buffer, 0, readBytes)
readBytes = in.read(buffer)
}
} finally {
in.close()
output0.close()
}
}

private object AbstractZincFile {
Expand Down

0 comments on commit 5a7012f

Please sign in to comment.