// extract the resource to the directory if it does not exist\r
File f = new File(toDir, resource.substring(path.length()));\r
if (!f.exists()) {\r
+ InputStream is = null;
+ OutputStream os = null;
try {\r
if (resource.charAt(resource.length() - 1) == '/') {\r
// directory\r
} else {\r
// file\r
f.getParentFile().mkdirs();\r
- InputStream is = context.getResourceAsStream(resource);\r
- OutputStream os = new FileOutputStream(f);\r
+ is = context.getResourceAsStream(resource);
+ os = new FileOutputStream(f);
byte [] buffer = new byte[4096];\r
int len = 0;\r
while ((len = is.read(buffer)) > -1) {\r
os.write(buffer, 0, len);\r
}\r
- is.close();\r
- os.close();\r
}\r
} catch (FileNotFoundException e) {\r
logger.error("Failed to find resource \"" + resource + "\"", e);\r
} catch (IOException e) {\r
logger.error("Failed to copy resource \"" + resource + "\" to " + f, e);\r
+ } finally {
+ if (is != null) {
+ try {
+ is.close();
+ } catch (IOException e) {
+ // ignore
+ }
+ }
+ if (os != null) {
+ try {
+ os.close();
+ } catch (IOException e) {
+ // ignore
+ }
+ }
}\r
}\r
}\r