close resources
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1747092 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
b8e38304f2
commit
60d35b92c6
@ -70,18 +70,24 @@ public abstract class POIDocument {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs from an old-style OPOIFS
|
* Constructs from an old-style OPOIFS
|
||||||
|
*
|
||||||
|
* @param fs the filesystem the document is read from
|
||||||
*/
|
*/
|
||||||
protected POIDocument(OPOIFSFileSystem fs) {
|
protected POIDocument(OPOIFSFileSystem fs) {
|
||||||
this(fs.getRoot());
|
this(fs.getRoot());
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Constructs from an old-style OPOIFS
|
* Constructs from an old-style OPOIFS
|
||||||
|
*
|
||||||
|
* @param fs the filesystem the document is read from
|
||||||
*/
|
*/
|
||||||
protected POIDocument(NPOIFSFileSystem fs) {
|
protected POIDocument(NPOIFSFileSystem fs) {
|
||||||
this(fs.getRoot());
|
this(fs.getRoot());
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Constructs from the default POIFS
|
* Constructs from the default POIFS
|
||||||
|
*
|
||||||
|
* @param fs the filesystem the document is read from
|
||||||
*/
|
*/
|
||||||
protected POIDocument(POIFSFileSystem fs) {
|
protected POIDocument(POIFSFileSystem fs) {
|
||||||
this(fs.getRoot());
|
this(fs.getRoot());
|
||||||
@ -180,49 +186,46 @@ public abstract class POIDocument {
|
|||||||
DirectoryNode dirNode = directory;
|
DirectoryNode dirNode = directory;
|
||||||
|
|
||||||
NPOIFSFileSystem encPoifs = null;
|
NPOIFSFileSystem encPoifs = null;
|
||||||
if (encryptionInfo != null) {
|
String step = "getting";
|
||||||
try {
|
try {
|
||||||
|
if (encryptionInfo != null) {
|
||||||
|
step = "getting encrypted";
|
||||||
InputStream is = encryptionInfo.getDecryptor().getDataStream(directory);
|
InputStream is = encryptionInfo.getDecryptor().getDataStream(directory);
|
||||||
|
try {
|
||||||
encPoifs = new NPOIFSFileSystem(is);
|
encPoifs = new NPOIFSFileSystem(is);
|
||||||
is.close();
|
|
||||||
dirNode = encPoifs.getRoot();
|
dirNode = encPoifs.getRoot();
|
||||||
} catch (Exception e) {
|
} finally {
|
||||||
logger.log(POILogger.ERROR, "Error getting encrypted property set with name " + setName, e);
|
is.close();
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//directory can be null when creating new documents
|
//directory can be null when creating new documents
|
||||||
if (dirNode == null || !dirNode.hasEntry(setName))
|
if (dirNode == null || !dirNode.hasEntry(setName)) {
|
||||||
return null;
|
|
||||||
|
|
||||||
DocumentInputStream dis;
|
|
||||||
try {
|
|
||||||
// Find the entry, and get an input stream for it
|
|
||||||
dis = dirNode.createDocumentInputStream( dirNode.getEntry(setName) );
|
|
||||||
} catch(IOException ie) {
|
|
||||||
// Oh well, doesn't exist
|
|
||||||
logger.log(POILogger.WARN, "Error getting property set with name " + setName + "\n" + ie);
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Find the entry, and get an input stream for it
|
||||||
|
step = "getting";
|
||||||
|
DocumentInputStream dis = dirNode.createDocumentInputStream( dirNode.getEntry(setName) );
|
||||||
try {
|
try {
|
||||||
// Create the Property Set
|
// Create the Property Set
|
||||||
PropertySet set = PropertySetFactory.create(dis);
|
step = "creating";
|
||||||
// Tidy up if needed
|
return PropertySetFactory.create(dis);
|
||||||
if (encPoifs != null) {
|
} finally {
|
||||||
encPoifs.close();
|
dis.close();
|
||||||
}
|
|
||||||
// Return the properties
|
|
||||||
return set;
|
|
||||||
} catch(IOException ie) {
|
|
||||||
// Must be corrupt or something like that
|
|
||||||
logger.log(POILogger.WARN, "Error creating property set with name " + setName + "\n" + ie);
|
|
||||||
} catch(org.apache.poi.hpsf.HPSFException he) {
|
|
||||||
// Oh well, doesn't exist
|
|
||||||
logger.log(POILogger.WARN, "Error creating property set with name " + setName + "\n" + he);
|
|
||||||
}
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.log(POILogger.WARN, "Error "+step+" property set with name " + setName, e);
|
||||||
return null;
|
return null;
|
||||||
|
} finally {
|
||||||
|
if (encPoifs != null) {
|
||||||
|
try {
|
||||||
|
encPoifs.close();
|
||||||
|
} catch(IOException e) {
|
||||||
|
logger.log(POILogger.WARN, "Error closing encrypted property poifs", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user