|
35 | 35 | import java.io.File; |
36 | 36 | import java.io.FileInputStream; |
37 | 37 | import java.io.IOException; |
| 38 | +import java.io.InputStream; |
38 | 39 | import java.net.URI; |
39 | 40 | import java.util.ArrayList; |
40 | 41 | import java.util.Collection; |
@@ -138,10 +139,23 @@ else if (f.getName().toLowerCase().endsWith(FileUtil.FILE_TYPE_LSF_COMPRESSED_BZ |
138 | 139 | File defsFile1 = new File(f.getParent()+"/IMC.xml"); |
139 | 140 | File defsFile2 = new File(f.getParent()+"/IMC.xml.gz"); |
140 | 141 | if(defsFile1.canRead()) { |
141 | | - defs = new IMCDefinition(new FileInputStream(defsFile1)); |
| 142 | + try (InputStream is = new FileInputStream(defsFile1)) { |
| 143 | + defs = new IMCDefinition(is); |
| 144 | + } |
| 145 | + catch (Exception e) { |
| 146 | + // defs = IMCDefinition.getInstance(); // If IMC.xml isn't present use the default ones |
| 147 | + throw new Exception(String.format("IMC definition was not loaded correctly.\n(cause: %s).\n" + |
| 148 | + "Fix it or try to load with default IMC (delete the IMC on the log folder).", e.getMessage()), e); |
| 149 | + } |
142 | 150 | } |
143 | 151 | else if (defsFile2.canRead()) { |
144 | | - defs = new IMCDefinition(new GzipCompressorInputStream(new FileInputStream(defsFile2), true)); |
| 152 | + try (InputStream is = new GzipCompressorInputStream(new FileInputStream(defsFile2), true)) { |
| 153 | + defs = new IMCDefinition(is); |
| 154 | + } catch (Exception e) { |
| 155 | + // defs = IMCDefinition.getInstance(); // If IMC.xml isn't present use the default ones |
| 156 | + throw new Exception(String.format("IMC definition was not loaded correctly.\n(cause: %s).\n" + |
| 157 | + "Fix it or try to load with default IMC (delete the IMC on the log folder).", e.getMessage()), e); |
| 158 | + } |
145 | 159 | } |
146 | 160 | else { |
147 | 161 | defs = IMCDefinition.getInstance(); // If IMC.xml isn't present use the default ones |
|
0 commit comments