【发布时间】:2011-08-09 22:12:07
【问题描述】:
我必须下载 HTTP 响应为“Transfer-Encoding: Chunked”的文件,因为我无法通过 «getContentLength» 为 DataInputStream 分配新的字节缓冲区。 你能建议我如何正确地做到这一点吗?
代码示例很简单:
try
{
dCon = (HttpURLConnection) new URL(torrentFileDownloadLink.absUrl("href")).openConnection();
dCon.setRequestProperty("Cookie", "session=" + cookies.get("session"));
dCon.setInstanceFollowRedirects(false);
dCon.setRequestMethod("GET");
dCon.setConnectTimeout(120000);
dCon.setReadTimeout(120000);
// byte[] downloadedFile == ???
DataInputStream br = new DataInputStream((dCon.getInputStream()));
br.readFully(downloadedFile);
System.out.println(downloadedFile);
} 捕捉(IOException ex) { Logger.getLogger(WhatCDWork.class.getName()).log(Level.SEVERE, null, ex); }
【问题讨论】:
标签: java chunked-encoding chunked http-chunked