Explicitly close IS
This commit is contained in:
parent
0700398f25
commit
c81861c3e5
|
@ -4,6 +4,7 @@ import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.mongodb.client.MongoDatabase;
|
import com.mongodb.client.MongoDatabase;
|
||||||
import lombok.Synchronized;
|
import lombok.Synchronized;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.commons.io.IOUtils;
|
||||||
import org.bson.Document;
|
import org.bson.Document;
|
||||||
import org.bson.types.ObjectId;
|
import org.bson.types.ObjectId;
|
||||||
import org.gcube.application.geoportal.common.faults.PathException;
|
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 org.gcube.data.transfer.library.faults.RemoteServiceException;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
@ -433,16 +435,21 @@ public class ConcessioniMongoManager extends MongoManager{
|
||||||
content.setActualContent(new ArrayList<PersistedContent>());
|
content.setActualContent(new ArrayList<PersistedContent>());
|
||||||
|
|
||||||
for(TempFile f : files) {
|
for(TempFile f : files) {
|
||||||
|
InputStream is=null;
|
||||||
try{
|
try{
|
||||||
log.debug("Opening temp file {}",f);
|
log.debug("Opening temp file {}",f);
|
||||||
String fileUrl=storage.getURL(f.getId());
|
String fileUrl=storage.getURL(f.getId());
|
||||||
log.debug("Got URL {} from ID {}",fileUrl,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));
|
"Imported via GeoPortal", sectionParent));
|
||||||
log.debug("Registered "+wsContent+" for "+content);
|
log.debug("Registered "+wsContent+" for "+content);
|
||||||
content.getActualContent().add(wsContent);
|
content.getActualContent().add(wsContent);
|
||||||
}catch(StorageHubException | IOException e){
|
}catch(StorageHubException | IOException e){
|
||||||
throw new StorageException("Unable to store "+f,e);
|
throw new StorageException("Unable to store "+f,e);
|
||||||
|
}finally{
|
||||||
|
if(is!=null)
|
||||||
|
IOUtils.closeQuietly(is);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
content.setMongo_id(asString(new ObjectId()));
|
content.setMongo_id(asString(new ObjectId()));
|
||||||
|
|
Loading…
Reference in New Issue