Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Download large files in RMI

 
Dhivya Krishnan
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi.,

I have a file in my server which is of huge size. Need to download that from my client.
Below is the method i use to read to do the same.

byte[] bytes = null;
File report = new File(absolutePath);
StringBuffer os = new StringBuffer();

if (report != null && report.exists() && report.isFile()) {
BufferedInputStream input = null;
try {
input = new BufferedInputStream(new FileInputStream(report));
bytes = new byte[(int) report.length()];
int buf = 1024;
int i=0;
while(true){

if(input.available() <= 1024){
input.read(bytes , buf*i, input.available());
break;
}
else
{
input.read(bytes , buf*i, buf);
}
i++;
}
....
.....
but it fails here bytes = new byte[(int) report.length()];

because the length of the file is too big.

Can you please suggest some other way to read large files in java.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12123
30
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you mean by "but it fails...because the length of the file is too big"? Does it die and do nothing? Do you get an error message and if so, what - EXACTLY - does it say? Does it do something else, and if so, what?

How do you know that is it failing because the file is too big?

You need to tell the details if you want any kind of reasonable help.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13061
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Why are you doing that? Why not simply write to a temp file as you get buffer loads - no reason to try to keep the whole thing in memory.

Bill
 
Dhivya Krishnan
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
getting this error: Exception in thread "main" java.lang.OutOfMemoryError: Java heap space

How do i get the temp file to my client side.?
 
Tim Moores
Bartender
Posts: 2794
38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
William Brogden wrote:Why not simply write to a temp file as you get buffer loads - no reason to try to keep the whole thing in memory.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic