5

I'm having a really strange problem. I'm trying to download some file and store. My code is relatively simple and straight forward (see below) and works fine on my local machine.

But it is intended to run on a Windows Terminal Server accessed through Citrix and a VPN. The file is to be saved to a mounted network drive. This mount is the local C:\ drive mounted through the Citrix VPN, so there might be some lag involved. Unfortunately I have no inside detail about how exactly the whole infrastructure is set up...

Now my problem is that the code below throws an IOException telling me there is no space left on the disk, when attempting to execute the write() call. The directory structure is created alright and a zero byte file is created, but content is never written.

There is more than a gigabyte space available on the drive, the Citrix client has been given "Full Access" permissions and copying/writing files on that mapped drive with Windows explorer or notepad works just fine. Only Java is giving me trouble here.

I also tried downloading to a temporary file first and then copying it to the destination, but since copying is basically the same stream operation as in my original code, there was no change in behavior. It still fails with a out of disk space exception.

I have no idea what else to try. Can you give any suggestions?

public boolean downloadToFile(URL url, File file){                                                                  
    boolean ok = false;                                                                                             

    try {                                                                                                           
        file.getParentFile().mkdirs();                                                                              

        BufferedInputStream  bis = new BufferedInputStream(url.openStream());                                       
        byte[]            buffer = new byte[2048];                                                                  
        FileOutputStream     fos = new FileOutputStream(file);                                                      
        BufferedOutputStream bos = new BufferedOutputStream( fos , buffer.length );                                 
        int size;                                                                                                   
        while ((size = bis.read(buffer, 0, buffer.length)) != -1) {                                                 
            bos.write(buffer, 0, size);                                                                             
        }                                                                                                           
        bos.flush();                                                                                                
        bos.close();                                                                                                
        bis.close();                                                                                                

        ok = true;                                                                                                  
    }catch(Exception e){                                                                                            
        e.printStackTrace();                                                                                        
    }                                                                                                               

    return ok;                                                                                                      
}
Andreas Gohr
  • 4,617
  • 5
  • 28
  • 45
  • Are you able to write files on that drive using other programs? – Martin Jul 07 '11 at 09:28
  • Update: I now "solved" my problem by downloading to a temporary file and then copying this file to the destination on the Citrix drive by executing Windows' xcopy command through ProcessBuilder. Of course that's an ugly hack and I'm still interested in a real solution here. – Andreas Gohr Jul 07 '11 at 09:35
  • The fact that Windows can write to the drive and Java cannot may indicate that the Java process does not have permission to write. Have you tried to run the Java process with Administrator privileges or else change the set up of the Citrix drive so non-Administrator programs can write to it. – rossum Jul 15 '11 at 10:55
  • 1
    The Java-Process is a signed Applet running inside a Citrix-exported Internet Explorer (but I'm having the same problem with a jar based application). Since calling xcopy from within the applet works, I don't think it's a permission problem (otherwise my xcopy call would be a privilege escalation vulnerability) – Andreas Gohr Jul 18 '11 at 11:44

1 Answers1

1

Have a try with commons-io. Esspecially the Util Classes FileUtils and IOUtils

After changing our code to use commons-io all file operations went much smouther. Even with mapped network drives.

powerMicha
  • 2,753
  • 1
  • 24
  • 31