Skip to content

Commit

Permalink
Merge pull request scala#10860 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
lrytz authored Sep 16, 2024
2 parents b6f70d2 + eb481e4 commit d835d98
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/sbt-bridge/scala/tools/xsbt/AbstractZincFile.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package scala.tools
package xsbt

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

private trait AbstractZincFile extends scala.reflect.io.AbstractFile {
def underlying: VirtualFile
Expand All @@ -29,7 +28,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 d835d98

Please sign in to comment.