mirror of https://github.com/apache/poi.git
Close resources correctly when opening encrypted documents in the TextExtractor
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1828378 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
166437912a
commit
1079e66ea7
|
@ -132,7 +132,7 @@ public class ExtractorFactory {
|
||||||
try {
|
try {
|
||||||
fs = new NPOIFSFileSystem(f);
|
fs = new NPOIFSFileSystem(f);
|
||||||
if (fs.getRoot().hasEntry(Decryptor.DEFAULT_POIFS_ENTRY)) {
|
if (fs.getRoot().hasEntry(Decryptor.DEFAULT_POIFS_ENTRY)) {
|
||||||
return createEncyptedOOXMLExtractor(fs);
|
return createEncryptedOOXMLExtractor(fs);
|
||||||
}
|
}
|
||||||
POIOLE2TextExtractor extractor = createExtractor(fs);
|
POIOLE2TextExtractor extractor = createExtractor(fs);
|
||||||
extractor.setFilesystem(fs);
|
extractor.setFilesystem(fs);
|
||||||
|
@ -161,7 +161,7 @@ public class ExtractorFactory {
|
||||||
case OLE2:
|
case OLE2:
|
||||||
NPOIFSFileSystem fs = new NPOIFSFileSystem(is);
|
NPOIFSFileSystem fs = new NPOIFSFileSystem(is);
|
||||||
boolean isEncrypted = fs.getRoot().hasEntry(Decryptor.DEFAULT_POIFS_ENTRY);
|
boolean isEncrypted = fs.getRoot().hasEntry(Decryptor.DEFAULT_POIFS_ENTRY);
|
||||||
return isEncrypted ? createEncyptedOOXMLExtractor(fs) : createExtractor(fs);
|
return isEncrypted ? createEncryptedOOXMLExtractor(fs) : createExtractor(fs);
|
||||||
case OOXML:
|
case OOXML:
|
||||||
return createExtractor(OPCPackage.open(is));
|
return createExtractor(OPCPackage.open(is));
|
||||||
default:
|
default:
|
||||||
|
@ -403,7 +403,7 @@ public class ExtractorFactory {
|
||||||
throw new IllegalStateException("Not yet supported");
|
throw new IllegalStateException("Not yet supported");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static POIXMLTextExtractor createEncyptedOOXMLExtractor(NPOIFSFileSystem fs)
|
private static POIXMLTextExtractor createEncryptedOOXMLExtractor(NPOIFSFileSystem fs)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
String pass = Biff8EncryptionKey.getCurrentUserPassword();
|
String pass = Biff8EncryptionKey.getCurrentUserPassword();
|
||||||
if (pass == null) {
|
if (pass == null) {
|
||||||
|
@ -425,6 +425,10 @@ public class ExtractorFactory {
|
||||||
throw new EncryptedDocumentException(e);
|
throw new EncryptedDocumentException(e);
|
||||||
} finally {
|
} finally {
|
||||||
IOUtils.closeQuietly(is);
|
IOUtils.closeQuietly(is);
|
||||||
|
|
||||||
|
// also close the NPOIFSFileSystem here as we read all the data
|
||||||
|
// while decrypting
|
||||||
|
fs.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue