mirror of
https://github.com/apache/poi.git
synced 2026-02-27 20:40:08 +08:00
close package parts when closing OPCPackage (#880)
* close package parts when closing OPCPackage * Update ZipPackagePart.java
This commit is contained in:
parent
e98a5991e7
commit
c0e6a9bed0
@ -681,6 +681,9 @@ public abstract class OPCPackage implements RelationshipSource, Closeable {
|
||||
// ensure all held resources are freed
|
||||
revert();
|
||||
|
||||
// ensure resources associated with package parts are closed
|
||||
closeParts();
|
||||
|
||||
// Clear
|
||||
this.contentTypeManager.clearAll();
|
||||
}
|
||||
@ -1870,6 +1873,10 @@ public abstract class OPCPackage implements RelationshipSource, Closeable {
|
||||
*/
|
||||
public abstract boolean isClosed();
|
||||
|
||||
protected void closeParts() {
|
||||
partList.closeParts();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "OPCPackage{" +
|
||||
|
||||
@ -112,8 +112,6 @@ public final class PackagePartCollection implements Serializable {
|
||||
return packagePartLookup.size();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get an unused part index based on the namePattern, which doesn't exist yet
|
||||
* and has the lowest positive index
|
||||
@ -141,4 +139,11 @@ public final class PackagePartCollection implements Serializable {
|
||||
.mapToInt(indexFromName)
|
||||
.collect(SparseBitSet::new, SparseBitSet::set, (s1,s2) -> s1.or(s2)).nextClearBit(1);
|
||||
}
|
||||
|
||||
// used to ensure resources are closed when they are no longer needed
|
||||
void closeParts() {
|
||||
for (PackagePart part : packagePartLookup.values()) {
|
||||
part.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -595,12 +595,15 @@ public final class ZipPackage extends OPCPackage {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ensure resources associated with package parts are closed
|
||||
closeParts();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a unique identifier to be use as a temp file name.
|
||||
* Create a unique identifier to be used as a temp file name.
|
||||
*
|
||||
* @return A unique identifier use to be use as a temp file name.
|
||||
* @return A unique identifier to be used as a temp file name.
|
||||
*/
|
||||
private synchronized String generateTempFileName(File directory) {
|
||||
File tmpFilename;
|
||||
|
||||
@ -134,14 +134,12 @@ public class ZipPackagePart extends PackagePart {
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotImplemented
|
||||
public void close() {
|
||||
throw new InvalidOperationException("Method not implemented !");
|
||||
// do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotImplemented
|
||||
public void flush() {
|
||||
throw new InvalidOperationException("Method not implemented !");
|
||||
// do nothing
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user