How to assemble the file using the range header?

北战南征 提交于 2020-01-02 20:18:09

问题


I use range hader, but not create correct file.

if I send Range bytes=0-8999 file weighs 9000 bytes and correct work. if I send Range bytes=0-8999,9000-9999 file weighs 10213 bytes and NOT correct work.

File type mp3.

What could be wrong?

HttpGet first = new HttpGet("http://cs4832.vkontakte.ru/u50184979/audio/ef64581d913c.mp3");
first.addHeader("Accept-Ranges", "bytes");
first.addHeader("Range", "bytes=0-8999,9000-9999");

//first.addHeader("Accept-Ranges", "bytes");

HttpResponse response = httpclient.execute(first, localContext);


InputStream instream = response.getEntity().getContent();
File f = new File("outFile1.mp3");

OutputStream out = new FileOutputStream(f);
byte buf[] = new byte[1024];
int len;
while ((len = instream.read(buf)) > 0) {
    out.write(buf, 0, len);
}
out.close();
instream.close();

回答1:


See RFC 2616, Section 14.16:

When an HTTP message includes the content of multiple ranges (for example, a response to a request for multiple non-overlapping ranges), these are transmitted as a multipart message. The multipart media type used for this purpose is "multipart/byteranges" as defined in Appendix 19.2. See Appendix 19.6.3 for a compatibility issue.



来源:https://stackoverflow.com/questions/5981564/how-to-assemble-the-file-using-the-range-header

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!