mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-09 15:25:56 -04:00
use ByteBuffer to deal with transferFrom
transferFrom giving us grief on some platforms (openjdk for arch and debian) ByteBuffer appears to be more reliable closes #3038 closes #3031
This commit is contained in:
parent
04a1fb77c9
commit
c67f700fa9
@ -2,6 +2,7 @@ package li.cil.oc.server.fs
|
||||
|
||||
import java.io
|
||||
import java.io.FileNotFoundException
|
||||
import java.nio.ByteBuffer
|
||||
import java.util.concurrent.CancellationException
|
||||
import java.util.concurrent.Future
|
||||
import java.util.concurrent.TimeUnit
|
||||
@ -131,7 +132,19 @@ trait Buffered extends OutputStreamFileSystem {
|
||||
childFile.createNewFile()
|
||||
val out = new io.FileOutputStream(childFile).getChannel
|
||||
val in = openInputChannel(childPath).get
|
||||
out.transferFrom(in, 0, Long.MaxValue)
|
||||
|
||||
val buffer = ByteBuffer.allocateDirect(16 * 1024)
|
||||
while (in.read(buffer) != -1) {
|
||||
buffer.flip()
|
||||
out.write(buffer)
|
||||
buffer.compact()
|
||||
}
|
||||
|
||||
buffer.flip()
|
||||
while (buffer.hasRemaining) {
|
||||
out.write(buffer)
|
||||
}
|
||||
|
||||
out.close()
|
||||
in.close()
|
||||
childFile.setLastModified(time)
|
||||
|
Loading…
x
Reference in New Issue
Block a user