close inputstream in case of errors while checking file for mdf errors

Signed-off-by: Viktor Stöhr <viktor.stoehr@efs-auto.com>
diff --git a/build.gradle b/build.gradle
index 0458dc4..857f715 100644
--- a/build.gradle
+++ b/build.gradle
@@ -11,26 +11,26 @@
  * SPDX-License-Identifier: EPL-2.0

  *

  ********************************************************************************/

-
-
-description = 'MDF Sorter'
-group = 'org.eclipse.mdm'
-version = '1.0.5'
-
-apply plugin: 'java'
-apply plugin: 'eclipse'
-
-repositories { mavenCentral() }
-
-dependencies { // testing
-	testCompile 'junit:junit:4.12' }
-
-tasks.withType(JavaCompile) {
-	sourceCompatibility = '1.7'
-	targetCompatibility = '1.7'
-}
-
-jar {
-	metaInf { from 'NOTICE.txt' }
-	metaInf { from 'LICENSE.txt' }
+

+

+description = 'MDF Sorter'

+group = 'org.eclipse.mdm'

+version = '1.0.6'

+

+apply plugin: 'java'

+apply plugin: 'eclipse'

+

+repositories { mavenCentral() }

+

+dependencies { // testing

+	testCompile 'junit:junit:4.12' }

+

+tasks.withType(JavaCompile) {

+	sourceCompatibility = '1.7'

+	targetCompatibility = '1.7'

+}

+

+jar {

+	metaInf { from 'NOTICE.txt' }

+	metaInf { from 'LICENSE.txt' }

 }
\ No newline at end of file
diff --git a/src/main/java/org/eclipse/mdm/mdfsorter/MDFSorter.java b/src/main/java/org/eclipse/mdm/mdfsorter/MDFSorter.java
index 2831075..ebf0377 100644
--- a/src/main/java/org/eclipse/mdm/mdfsorter/MDFSorter.java
+++ b/src/main/java/org/eclipse/mdm/mdfsorter/MDFSorter.java
@@ -43,7 +43,7 @@
 	/**
 	 * Version of this tool as String. (Used in the file Header)
 	 */
-	public static final String VERSIONSTRING = "1.0.5";
+	public static final String VERSIONSTRING = "1.0.6";
 
 	/**
 	 * The logger for this application
@@ -188,32 +188,31 @@
 	 *             If an I/O error occurs.
 	 */
 	static boolean checkForProblems(ArgumentStruct struct) throws IOException {
-		setUpLogging();
-		FileInputStream bufstream;
-		bufstream = new FileInputStream(struct.inputname);
-		log.log(Level.INFO, "File opened.");
-		// 1. Parse file and get Content-Struct
-		MDFFileContent<? extends MDFGenBlock> con = MDFParser.serializeFile(bufstream.getChannel());
-
-		// 2. Check for Problems.
-		boolean ret = false;
-		if (!con.isMDF3()) {
-			@SuppressWarnings("unchecked")
-			MDF4ProcessWriter pw = new MDF4ProcessWriter((MDFFileContent<MDF4GenBlock>) con, struct);
-			ret = pw.checkProblems();
-		} else {
-			@SuppressWarnings("unchecked")
-			MDF3ProcessWriter pw = new MDF3ProcessWriter((MDFFileContent<MDF3GenBlock>) con, struct);
-			ret = pw.checkProblems();
+		setUpLogging();

+		try (FileInputStream bufstream = new FileInputStream(struct.inputname)) {
+			log.log(Level.INFO, "File opened.");
+			// 1. Parse file and get Content-Struct
+			MDFFileContent<? extends MDFGenBlock> con = MDFParser.serializeFile(bufstream.getChannel());
+	
+			// 2. Check for Problems.
+			boolean ret = false;
+			if (!con.isMDF3()) {
+				@SuppressWarnings("unchecked")
+				MDF4ProcessWriter pw = new MDF4ProcessWriter((MDFFileContent<MDF4GenBlock>) con, struct);
+				ret = pw.checkProblems();
+			} else {
+				@SuppressWarnings("unchecked")
+				MDF3ProcessWriter pw = new MDF3ProcessWriter((MDFFileContent<MDF3GenBlock>) con, struct);
+				ret = pw.checkProblems();
+			}
+	
+			if (ret) {
+				log.info("Problems were found. Processing file recommended.");
+			} else {
+				log.info("No problems were found. This file needn't be processed.");
+			}
+			return ret;

 		}
-
-		if (ret) {
-			log.info("Problems were found. Processing file recommended.");
-		} else {
-			log.info("No problems were found. This file needn't be processed.");
-		}
-		bufstream.close();
-		return ret;
 	}
 
 	/**