Skip to content

Commit

Permalink
Copy bytes directly instead of using scala.reflect.io.Streamable subo…
Browse files Browse the repository at this point in the history
…ptimal methods
  • Loading branch information
rochala committed Sep 11, 2024
1 parent 574dd92 commit ed57d0e
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 ed57d0e

Please sign in to comment.