* @throws IOException if an error occurs while reading the data\r
* @throws EncryptedDocumentException If the wrong password is given for a protected file\r
*/\r
- @SuppressWarnings("resource")\r
public static SlideShow<?,?> create(InputStream inp, String password) throws IOException, EncryptedDocumentException {\r
// If clearly doesn't do mark/reset, wrap up\r
if (! inp.markSupported()) {\r
* @throws IOException if an error occurs while reading the data\r
* @throws EncryptedDocumentException If the wrong password is given for a protected file\r
*/\r
- @SuppressWarnings("resource")\r
public static SlideShow<?,?> create(File file, String password, boolean readOnly) throws IOException, EncryptedDocumentException {\r
if (!file.exists()) {\r
throw new FileNotFoundException(file.toString());\r
}\r
\r
+ NPOIFSFileSystem fs = null;\r
try {\r
- NPOIFSFileSystem fs = new NPOIFSFileSystem(file, readOnly);\r
+ fs = new NPOIFSFileSystem(file, readOnly);\r
return create(fs, password);\r
} catch(OfficeXmlFileException e) {\r
+ if(fs != null) {\r
+ fs.close();\r
+ }\r
return createXSLFSlideShow(file, readOnly);\r
+ } catch(RuntimeException e) {\r
+ if(fs != null) {\r
+ fs.close();\r
+ }\r
+ throw e;\r
}\r
}\r
\r
try {
NPOIFSFileSystem fs = new NPOIFSFileSystem(file, readOnly);
- return create(fs, password);
+ try {
+ return create(fs, password);
+ } catch (RuntimeException e) {
+ // ensure that the file-handle is closed again
+ fs.close();
+
+ throw e;
+ }
} catch(OfficeXmlFileException e) {
// opening as .xls failed => try opening as .xlsx
OPCPackage pkg = OPCPackage.open(file, readOnly ? PackageAccess.READ : PackageAccess.READ_WRITE);
// rethrow exception
throw ioe;
- } catch (IllegalArgumentException ioe) {
+ } catch (RuntimeException ioe) {
// ensure that file handles are closed (use revert() to not re-write the file)
pkg.revert();
//pkg.close();