moved to method deleteOnExit for temporary preview images

git-svn-id: https://svn.research-infrastructures.eu/d4science/gcube/trunk/portlets/user/share-updates@134214 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Costantino Perciante 2016-11-16 08:33:49 +00:00
parent f56a37ee15
commit 6e23bf8fbf
1 changed files with 4 additions and 8 deletions

View File

@ -245,16 +245,18 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar
//generate the random dir
File theRandomDir = new File(UPLOAD_LOCATION_LOCAL + File.separator + UUID.randomUUID().toString());
theRandomDir.mkdir();
theRandomDir.deleteOnExit();
_log.debug("Created temp upload directory in: " + theRandomDir);
// generate a random file name and create it under the randomDir
File file = new File(theRandomDir, UUID.randomUUID().toString().substring(0, 10));
file.deleteOnExit();
//Get the inputstream and copy there
URL url = new URL(urlThumbnail);
Streams.copy(url.openStream(), new FileOutputStream(file), true);
_log.debug("File is at " + file.getAbsolutePath());
return file;
}else
return null;
@ -289,12 +291,6 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar
break;
default: break;
}
//delete file and folder
File parentDir = localFile.getParentFile();
localFile.delete();
parentDir.delete();
return thumbnailUrlFTP;
} catch (IOException e) {
_log.error("Error while saving thumbnail on ftp", e);
@ -302,7 +298,7 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar
}
}else
_log.warn("the file at url " + urlThumbnail + " doesn't exist");
return null;
}