diff --git a/main/src/main/scala/sbt/internal/graph/rendering/TreeView.scala b/main/src/main/scala/sbt/internal/graph/rendering/TreeView.scala index 36b2b6d80..9dea1d56c 100644 --- a/main/src/main/scala/sbt/internal/graph/rendering/TreeView.scala +++ b/main/src/main/scala/sbt/internal/graph/rendering/TreeView.scala @@ -17,7 +17,6 @@ import sjsonnew.support.scalajson.unsafe.{ CompactPrinter, Converter } import java.io.{ File, FileOutputStream, InputStream, OutputStream } import java.net.URI -import scala.annotation.tailrec object TreeView { def createJson(graph: ModuleGraph): String = { @@ -79,17 +78,6 @@ object TreeView { } } - def copy(from: InputStream, to: OutputStream): Unit = { - val buffer = new Array[Byte](65536) - - @tailrec def rec(): Unit = { - val read = from.read(buffer) - if (read > 0) { - to.write(buffer, 0, read) - rec() - } else if (read == 0) - throw new IllegalStateException("InputStream.read returned 0") - } - rec() - } + def copy(from: InputStream, to: OutputStream): Unit = + from.transferTo(to) } diff --git a/sbt-app/src/sbt-test/dependency-management/ivyless-publish-http/project/HttpPutServer.scala b/sbt-app/src/sbt-test/dependency-management/ivyless-publish-http/project/HttpPutServer.scala index 439ce62b7..d0337491d 100644 --- a/sbt-app/src/sbt-test/dependency-management/ivyless-publish-http/project/HttpPutServer.scala +++ b/sbt-app/src/sbt-test/dependency-management/ivyless-publish-http/project/HttpPutServer.scala @@ -21,9 +21,7 @@ object HttpPutServer { val in = ex.getRequestBody val out = new FileOutputStream(targetFile) try { - val buf = new Array[Byte](8192) - var n = 0 - while ({ n = in.read(buf); n } != -1) out.write(buf, 0, n) + in.transferTo(out) } finally { out.close() in.close() diff --git a/sbt-app/src/sbt-test/dependency-management/ivyless-publish-maven-http/project/HttpPutServer.scala b/sbt-app/src/sbt-test/dependency-management/ivyless-publish-maven-http/project/HttpPutServer.scala index ccbc66d57..a801fdf1d 100644 --- a/sbt-app/src/sbt-test/dependency-management/ivyless-publish-maven-http/project/HttpPutServer.scala +++ b/sbt-app/src/sbt-test/dependency-management/ivyless-publish-maven-http/project/HttpPutServer.scala @@ -20,9 +20,7 @@ object HttpPutServer { val in = ex.getRequestBody val out = new FileOutputStream(targetFile) try { - val buf = new Array[Byte](8192) - var n = 0 - while ({ n = in.read(buf); n } != -1) out.write(buf, 0, n) + in.transferTo(out) } finally { out.close() in.close() diff --git a/sbt-app/src/sbt-test/lm-coursier/from/build.sbt b/sbt-app/src/sbt-test/lm-coursier/from/build.sbt index b19466af7..3c4f13462 100644 --- a/sbt-app/src/sbt-test/lm-coursier/from/build.sbt +++ b/sbt-app/src/sbt-test/lm-coursier/from/build.sbt @@ -14,14 +14,7 @@ libraryDependencies += "com.chuusai" %% "shapeless" % "2.3.41" from { val is = url.openStream() val os = new java.io.FileOutputStream(f) - var read = -1 - val b = new Array[Byte](16*1024) - while ({ - read = is.read(b) - read >= 0 - }) { - os.write(b, 0, read) - } + is.transferTo(os) is.close() os.close()