我有一個二進制文件,我需要從start: Long
- end: Long
中提取一些字節範圍。我需要Long
,因爲有幾個gigagbytes。我的應用程序需要將結果返回爲ByteString
。我試圖從Scala文件中提取字節的範圍
val content: Array[Byte] = Array()
val stream: FileInputStream = new FileInputStream(file: File)
stream.skip(start)
stream.read(content, 0, end-start)
,但我已經不能在read
使用Long
,只有Int
(這是一個錯誤?skip
是確定與Long
......)。此外,我需要將結果轉換爲ByteString
。我也很想做到這一點:
val stream: FileInputStream = new FileInputStream(file: File)
stream.skip(start)
org.apache.commons.io.IOUtils.toByteArray(stream)
但我該如何告訴它在哪裏結束? stream
沒有方法takeWhile
或take
。然後我試圖
val source = scala.io.Source.fromFile(file: File)
source.drop(start).take(end-start)
同樣,只有在drop
Int
...
我怎麼能這樣做?
http://stackoverflow.com/questions/28883876/can-i-do-a-lazy-take-with-a-long-parameter –
有了,我是試圖在Play中實現對字節範圍請求的正確響應,但是自從最近Play似乎已經實現了這個功能,並將其記錄在「使用公共資產」中... – JulienD