close streams if an exception is throw

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1751983 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Javen O'Neal 2016-07-09 06:30:12 +00:00
parent 909c07f37f
commit ca22a79e01

View File

@ -63,9 +63,13 @@ public class POIFSDump {
System.out.println("Dumping " + filename); System.out.println("Dumping " + filename);
FileInputStream is = new FileInputStream(filename); FileInputStream is = new FileInputStream(filename);
NPOIFSFileSystem fs = new NPOIFSFileSystem(is); NPOIFSFileSystem fs;
try {
fs = new NPOIFSFileSystem(is);
} finally {
is.close(); is.close();
}
try {
DirectoryEntry root = fs.getRoot(); DirectoryEntry root = fs.getRoot();
File file = new File(new File(filename).getName(), root.getName()); File file = new File(new File(filename).getName(), root.getName());
if (!file.exists() && !file.mkdirs()) { if (!file.exists() && !file.mkdirs()) {
@ -87,10 +91,11 @@ public class POIFSDump {
dump(fs, startBlock, "mini-stream", file); dump(fs, startBlock, "mini-stream", file);
} }
} }
} finally {
fs.close(); fs.close();
} }
} }
}
public static void dump(DirectoryEntry root, File parent) throws IOException { public static void dump(DirectoryEntry root, File parent) throws IOException {
for(Iterator<Entry> it = root.getEntries(); it.hasNext();){ for(Iterator<Entry> it = root.getEntries(); it.hasNext();){