我想使用 scalaj-http 库从 http 连接下载大小为 31gb 的字节内容文件。'asBytes' 不是一个选项,因为它返回一个字节数组。
我尝试使用返回输入流的“执行”方法,但是当我执行下面的程序时,它返回流已关闭。我不认为我正在阅读两次流。
我做错了什么?
val response: HttpResponse[InputStream] = Http(url).postForm(parameters).execute(inputStream => inputStream)
if (response.isError) println(s"Sorry, error found: ${response.code}")
else {
val is: InputStream = response.body
val buffer: Array[Byte] = Array.ofDim[Byte](1024)
val fos = new FileOutputStream("xxx")
var read: Int = 0
while (read >= 0) {
read = is.read(buffer)
if (read > 0) {
fos.write(buffer, 0, read)
}
}
fos.close()
}