void test() throws Exception {
File file = new File("test-data/publisher/SampleBrochure.pub");
- InputStream stream = new FileInputStream(file);
- try {
+ try (InputStream stream = new FileInputStream(file)) {
handleFile(stream, file.getPath());
- } finally {
- stream.close();
}
handleExtracting(file);
- stream = new FileInputStream(file);
- try {
+ try (InputStream stream = new FileInputStream(file)) {
try (PublisherTextExtractor extractor = new PublisherTextExtractor(stream)) {
assertNotNull(extractor.getText());
}
- } finally {
- stream.close();
}
}
import org.apache.commons.io.input.UnsynchronizedByteArrayInputStream;
import org.apache.poi.poifs.filesystem.DirectoryNode;
+import org.apache.poi.poifs.filesystem.Entry;
import org.apache.poi.util.IOUtils;
/**
DirectoryNode dir = baseDir;
for(int i=0; i<path.length-1; i++) {
try {
- dir = (DirectoryNode)dir.getEntry(path[i]);
+ Entry entry = dir.getEntry(path[i]);
+ if (!(entry instanceof DirectoryNode)) {
+ throw new IllegalArgumentException("Had unexpected type of entry for path: " + path[i] + ": " + entry);
+ }
+ dir = (DirectoryNode) entry;
} catch (FileNotFoundException e) {
throw new IllegalArgumentException("File invalid - failed to find directory entry '"
+ path[i] + "': " + e);