1

i have used a java code to download a file from a server and after the file is downloaded the file gets deleted from the server. The total size of file is 200gb. the downloading starts and shows download successful. when i check the downloaded file size its only 3.3 gb. and also the file does not get deleted. i have checked the error logs but there is no log. here is my code.

byte b[] = new byte[2048];

int len = 0;
filein = new BufferedInputStream(new FileInputStream(file));
output = new BufferedOutputStream(response.getOutputStream());
response.setContentType("application/force-download");
response.setHeader("content-Disposition", "attachment; filename=" + fname);  // downloaded file name
response.setHeader("content-Transfer-Encoding", "binary");
while ((len = filein.read(b)) > 0) {
    output.write(b, 0, len);

    output.flush();
}
output.close();
filein.close();
file.delete();  // delete file

please suggest what i am missing..

anonymous
  • 244
  • 2
  • 4
  • 23
  • You have got to be kidding. 200 gigabytes? I don't know of an internet service that lets you download more than 150 GB a month. – tbodt Jul 30 '13 at 09:35
  • I seems like a bad idea to delete the file without checking if the download was successful. – Dahaka Jul 30 '13 at 09:37
  • @Dahaka according to the code the file should get deleted after succesful download, but it does not get deleted. – anonymous Jul 30 '13 at 09:38
  • You're sure there is no IOException? I can't think of any other reason it would not delete the file. – tbodt Jul 30 '13 at 09:39
  • 4
    Are you sure the file system you are writing to can handle files larger than 3.3GB and have you also checked that the exception is silently catched somewhere? If no exception would be thrown than the file should get deleted. – ssindelar Jul 30 '13 at 09:40
  • On what kind of filesystem are you storing the file? – mthmulders Jul 30 '13 at 09:43
  • the file system is UFS, its a solaris machine – anonymous Jul 30 '13 at 09:44
  • and there is nothing in the logs... no exception – anonymous Jul 30 '13 at 09:44
  • 1
    3.3gb sounds like the 32-bit maximum, similar to Windows only being able to address up to 3.3GB memory on 32-bit. – skiwi Jul 30 '13 at 09:45
  • How are you running this program? If from the command line then I believe you about no exception, unless it is silently caught. – tbodt Jul 30 '13 at 09:45
  • its a small web application, so that the user selects the file to download and then the file is been downloaded. its on glassfish server. i have chaecked all the logs – anonymous Jul 30 '13 at 09:46
  • How did you create 200 Gb file? Which application will handle that file.. – Shashi Jul 30 '13 at 09:59
  • Since even a BlueRay is less than 100GB, I guess the files are: 1) Backup Volumes (or Encrypted Volumes) 2) Virtual Machines 3) Databases 4) RedRay Movies – Andrea Ligios Jul 30 '13 at 12:19

1 Answers1

1

I think your server kills the download (end the response) after the response starts taking up too much size in memory. Check to see if available memory is an issue. Linux has a daemon which will simply kill high-mem-usage processes if things start to get critical.

If the server abruptly ends the response it might be that the client (browser) still thinks the download is succesfull. That would also explain why the file doesn't get deleted if it's an exception that's being thrown.

I'd wrap the while-loop in a try{..}catch(Throwable t)//catches all exceptions and errors and see what happens.

Buurman
  • 1,914
  • 17
  • 26
  • +1 You've said *exactly* the same things I was planning to write after the lunch break :) catching the Throwable (watching for daemons) and [checking the memory](http://stackoverflow.com/a/25596/1654265); I'd add [checking the file system limitations too](http://www.sunsolarisadmin.com/general/ufs-maximum-file-size-2gb-restriction-in-sun-solaris/), on Solaris there are a lot of different ways for this to happen – Andrea Ligios Jul 30 '13 at 12:16