hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From olaf.ha...@notes.uni-paderborn.de
Subject Problem posting file and deleting it afterwards
Date Sat, 15 Mar 2003 16:40:37 GMT
I send a file on the harddisk using class "FilePart" and everything works
fine.
But it is just a temporary file which should be deleted afterwards sending
it, but File.delete() fails and the file remains on the disk (based on
alpha 3). As far as I found out, the method "sendData" creates an
inputStream from the file, but did not close it at any time, so the file is
still locked after sending. So my fix is to close this InputStream after
all data is send (line marked with +). I do not know if this has any side
effects or other problems, but my problem would be fixed.

What do you think?

Regards,
Olaf


   protected void sendData(OutputStream out) throws IOException {
      LOG.trace("enter sendData(OutputStream out)");
      if (lengthOfData() == 0) {

       // this file contains no data, so there is nothing to send.
       // we don't want to create a zero length buffer as this will
       // cause an infinite loop when reading.
       LOG.debug("No data to send.");
       return;
     }

     byte[] tmp = new byte[4096];
     InputStream instream = source.createInputStream();

     int len;
     while ((len = instream.read(tmp)) >= 0) {
        out.write(tmp, 0, len);
     }

+   instream.close();
  }





Mime
View raw message