i use HttpUrlConnection and inputstream and bufferedInputStream and outputstream and BufferedOutputstream to download file from my wampserver , and it work correctly but when i trace may taskmanager and performence tab i see that my ram increase very much from 2.02 GB to about 3 GB :
this my code :
private void downloadFile() {
try {
this.response = this.con.getInputStream();
this.bis = new BufferedInputStream(this.response, 1024 * 1024);
this.responseContentSize = this.con.getContentLength();
if (this.responseContentSize == (this.end_range - this.start_range) + 1) {
byte buffer[] = new byte[MAX_BUFFER_SIZE];
makeTmpFile();
out = new FileOutputStream(this.tmpdir + this.tmpFilename);
bos = new BufferedOutputStream(out, 1024 * 1024);
while (true) {
int read = bis.read(buffer, 0, this.MAX_BUFFER_SIZE);
if (read == -1)
break;
bos.write(buffer, 0, read);
downloadedBytes += read;
}
if (bos != null)
bos.close();
if (out != null)
out.close();
if (fpointer != null)
fpointer.close();
if (bis != null)
bis.close();
if (response != null)
response.close();
2);//finish
}
} catch (IOException e) {
sharedDownloadStatus.setCell(this.threadIndex, STATUS, 0);//error
log.setLog("func : downloadFile =>\n couldnt download file\n" + e.getMessage());
}
}
i created this func in class that implement Runnable to begin its task in another thread