fix: resource leak during archive usage
package org.openbaton.tosca.parser;
-import java.io.BufferedReader;
-import java.io.ByteArrayInputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
+import java.io.*;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.zip.ZipEntry;
@@ -36,14 +30,7 @@ import org.openbaton.catalogue.nfvo.Script;
import org.openbaton.catalogue.nfvo.VNFPackage;
import org.openbaton.catalogue.nfvo.images.BaseNfvImage;
import org.openbaton.catalogue.nfvo.images.NFVImage;
-import org.openbaton.exceptions.AlreadyExistingException;
-import org.openbaton.exceptions.BadFormatException;
-import org.openbaton.exceptions.BadRequestException;
-import org.openbaton.exceptions.EntityUnreachableException;
-import org.openbaton.exceptions.IncompatibleVNFPackage;
-import org.openbaton.exceptions.NotFoundException;
-import org.openbaton.exceptions.PluginException;
-import org.openbaton.exceptions.VimException;
+import org.openbaton.exceptions.*;
import org.openbaton.nfvo.core.interfaces.VNFPackageManagement;
import org.openbaton.nfvo.repositories.VNFDRepository;
import org.openbaton.nfvo.repositories.VnfPackageRepository;
@@ -81,13 +68,12 @@ public class CSARParser {
private void readFiles(InputStream csar_file) throws IOException, NotFoundException {
- ZipInputStream zipStream = new ZipInputStream(csar_file);
ZipEntry entry;
this.scripts.clear();
this.folderNames.clear();
this.template = new ByteArrayOutputStream();
this.metadata = new ByteArrayOutputStream();
-
+ try (ZipInputStream zipStream = new ZipInputStream(csar_file)) {
while ((entry = zipStream.getNextEntry()) != null) {
if (!entry.isDirectory()) {
@@ -125,6 +111,7 @@ public class CSARParser {
}
}
}
+ }
if (this.metadata == null) {
throw new NotFoundException("CSARParser: You have to include the TOSCA.meta");
}
@@ -134,8 +121,6 @@ public class CSARParser {
if (this.template == null) {
throw new NotFoundException("CSARParser: No NSD or VNFD Template found");
}
-
- //zipStream.close();
}
private void readMetaData() throws IOException {
