我必须下载 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);
}
catch(IOException ex)
{
Logger.getLogger(WhatCDWork.class.getName()).log(Level.SEVERE, null, ex);
}