Explicitly close IS

sg-core-3
Fabio Sinibaldi 3 years ago
parent 0700398f25
commit c81861c3e5

@ -4,6 +4,7 @@ import com.fasterxml.jackson.core.JsonProcessingException;
import com.mongodb.client.MongoDatabase;
import lombok.Synchronized;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.IOUtils;
import org.bson.Document;
import org.bson.types.ObjectId;
import org.gcube.application.geoportal.common.faults.PathException;
@ -28,6 +29,7 @@ import org.gcube.common.storagehub.model.exceptions.StorageHubException;
import org.gcube.data.transfer.library.faults.RemoteServiceException;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.sql.SQLException;
@ -433,16 +435,21 @@ public class ConcessioniMongoManager extends MongoManager{
content.setActualContent(new ArrayList<PersistedContent>());
for(TempFile f : files) {
InputStream is=null;
try{
log.debug("Opening temp file {}",f);
String fileUrl=storage.getURL(f.getId());
log.debug("Got URL {} from ID {}",fileUrl,f.getId());
WorkspaceContent wsContent=ws.storeToWS(new FileOptions(f.getFilename(),new URL(fileUrl).openStream(),
is=new URL(fileUrl).openStream();
WorkspaceContent wsContent=ws.storeToWS(new FileOptions(f.getFilename(),is,
"Imported via GeoPortal", sectionParent));
log.debug("Registered "+wsContent+" for "+content);
content.getActualContent().add(wsContent);
}catch(StorageHubException | IOException e){
throw new StorageException("Unable to store "+f,e);
}finally{
if(is!=null)
IOUtils.closeQuietly(is);
}
}
content.setMongo_id(asString(new ObjectId()));

Loading…
Cancel
Save