Author: nick
Date: Fri Apr 25 22:00:30 2014
New Revision: 1590160
URL: http://svn.apache.org/r1590160
Log:
When deleting a document in NPOIFS, free the underlying blocks
Modified:
poi/trunk/src/java/org/apache/poi/poifs/filesystem/DirectoryNode.java
poi/trunk/src/java/org/apache/poi/poifs/filesystem/NPOIFSDocument.java
poi/trunk/src/java/org/apache/poi/poifs/filesystem/NPOIFSFileSystem.java
Modified: poi/trunk/src/java/org/apache/poi/poifs/filesystem/DirectoryNode.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/poifs/filesystem/DirectoryNode.java?rev=1590160&r1=1590159&r2=1590160&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/poifs/filesystem/DirectoryNode.java
(original)
+++ poi/trunk/src/java/org/apache/poi/poifs/filesystem/DirectoryNode.java Fri
Apr 25 22:00:30 2014
@@ -290,13 +290,17 @@ public class DirectoryNode
if (rval)
{
_entries.remove(entry);
- _byname.remove(entry.getName());
+ _byname.remove(entry.getName());
- if(_ofilesystem != null) {
- _ofilesystem.remove(entry);
- } else {
- _nfilesystem.remove(entry);
- }
+ if(_ofilesystem != null) {
+ _ofilesystem.remove(entry);
+ } else {
+ try {
+ _nfilesystem.remove(entry);
+ } catch (IOException e) {
+ // TODO Work out how to report this, given we can't change
the method signature...
+ }
+ }
}
return rval;
}
Modified: poi/trunk/src/java/org/apache/poi/poifs/filesystem/NPOIFSDocument.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/poifs/filesystem/NPOIFSDocument.java?rev=1590160&r1=1590159&r2=1590160&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/poifs/filesystem/NPOIFSDocument.java
(original)
+++ poi/trunk/src/java/org/apache/poi/poifs/filesystem/NPOIFSDocument.java Fri
Apr 25 22:00:30 2014
@@ -128,6 +128,14 @@ public final class NPOIFSDocument implem
_property.setStartBlock(_stream.getStartBlock());
}
+ /**
+ * Frees the underlying stream and property
+ */
+ void free() throws IOException {
+ _stream.free();
+ _property.setStartBlock(POIFSConstants.END_OF_CHAIN);
+ }
+
int getDocumentBlockSize() {
return _block_size;
}
Modified:
poi/trunk/src/java/org/apache/poi/poifs/filesystem/NPOIFSFileSystem.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/poifs/filesystem/NPOIFSFileSystem.java?rev=1590160&r1=1590159&r2=1590160&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/poifs/filesystem/NPOIFSFileSystem.java
(original)
+++ poi/trunk/src/java/org/apache/poi/poifs/filesystem/NPOIFSFileSystem.java
Fri Apr 25 22:00:30 2014
@@ -44,6 +44,7 @@ import org.apache.poi.poifs.nio.ByteArra
import org.apache.poi.poifs.nio.DataSource;
import org.apache.poi.poifs.nio.FileBackedDataSource;
import org.apache.poi.poifs.property.DirectoryProperty;
+import org.apache.poi.poifs.property.DocumentProperty;
import org.apache.poi.poifs.property.NPropertyTable;
import org.apache.poi.poifs.storage.BATBlock;
import org.apache.poi.poifs.storage.BATBlock.BATBlockAndIndex;
@@ -431,7 +432,11 @@ public class NPOIFSFileSystem extends Bl
// The header block doesn't count, so add one
long blockWanted = offset + 1;
long startAt = blockWanted * bigBlockSize.getBigBlockSize();
- return _data.read(bigBlockSize.getBigBlockSize(), startAt);
+ try {
+ return _data.read(bigBlockSize.getBigBlockSize(), startAt);
+ } catch (IndexOutOfBoundsException e) {
+ throw new IndexOutOfBoundsException("Block " + offset + " not found
- " + e);
+ }
}
/**
@@ -820,9 +825,15 @@ public class NPOIFSFileSystem extends Bl
*
* @param entry to be removed
*/
-
- void remove(EntryNode entry)
+ void remove(EntryNode entry) throws IOException
{
+ // If it's a document, free the blocks
+ if (entry instanceof DocumentEntry) {
+ NPOIFSDocument doc = new
NPOIFSDocument((DocumentProperty)entry.getProperty(), this);
+ doc.free();
+ }
+
+ // Now zap it from the properties list
_property_table.removeProperty(entry.getProperty());
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]