Skip to content

Commit

Permalink
fix: javalib many Files.copy methods now use multi-byte I/O (#3915)
Browse files Browse the repository at this point in the history
  • Loading branch information
LeeTibbert committed May 13, 2024
1 parent cee597b commit dda6644
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 12 deletions.
2 changes: 1 addition & 1 deletion javalib/src/main/scala/java/io/InputStream.scala
Expand Up @@ -129,7 +129,7 @@ abstract class InputStream extends Closeable {
/** Java 9
*/
def transferTo(out: OutputStream): Long = {
val limit = 1024
val limit = 4096 // sector & page sizes on most architectures circa 2024
val buffer = new Array[Byte](limit)

var nTransferred = 0L
Expand Down
13 changes: 2 additions & 11 deletions javalib/src/main/scala/java/nio/file/Files.scala
Expand Up @@ -137,17 +137,8 @@ object Files {
target
}

private def copy(in: InputStream, out: OutputStream): Long = {
var written: Long = 0L
var value: Int = 0

while ({ value = in.read(); value != -1 }) {
out.write(value)
written += 1
}

written
}
private def copy(in: InputStream, out: OutputStream): Long =
in.transferTo(out)

def createDirectories(dir: Path, attrs: Array[FileAttribute[_]]): Path =
if (exists(dir, Array.empty) && !isDirectory(dir, Array.empty))
Expand Down

0 comments on commit dda6644

Please sign in to comment.