aboutsummaryrefslogtreecommitdiffstats
path: root/src/java
diff options
context:
space:
mode:
authorNick Burch <nick@apache.org>2015-07-06 21:15:57 +0000
committerNick Burch <nick@apache.org>2015-07-06 21:15:57 +0000
commit92764ff10d3059218b67fd5a15cb7c37db30bcd7 (patch)
treebc34f5f7ffd044a15ab23509393bb5ca1969afb8 /src/java
parentdf179170a23934654ec8836fc6bc1139b9077bec (diff)
downloadpoi-92764ff10d3059218b67fd5a15cb7c37db30bcd7.tar.gz
poi-92764ff10d3059218b67fd5a15cb7c37db30bcd7.zip
Helper method to report the number of blocks used in a BAT
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1689504 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java')
-rw-r--r--src/java/org/apache/poi/poifs/storage/BATBlock.java17
1 files changed, 15 insertions, 2 deletions
diff --git a/src/java/org/apache/poi/poifs/storage/BATBlock.java b/src/java/org/apache/poi/poifs/storage/BATBlock.java
index 8712e65f6f..53099644ac 100644
--- a/src/java/org/apache/poi/poifs/storage/BATBlock.java
+++ b/src/java/org/apache/poi/poifs/storage/BATBlock.java
@@ -30,8 +30,6 @@ import org.apache.poi.util.LittleEndian;
/**
* A block of block allocation table entries. BATBlocks are created
* only through a static factory method: createBATBlocks.
- *
- * @author Marc Johnson (mjohnson at apache dot org)
*/
public final class BATBlock extends BigBlock {
/**
@@ -301,6 +299,21 @@ public final class BATBlock extends BigBlock {
public boolean hasFreeSectors() {
return _has_free_sectors;
}
+ /**
+ * How many sectors in this block are taken?
+ * Note that calling {@link #hasFreeSectors()} is much quicker
+ */
+ public int getUsedSectors(boolean isAnXBAT) {
+ int usedSectors = 0;
+ int toCheck = _values.length;
+ if (isAnXBAT) toCheck--; // Last is a chain location
+ for(int k=0; k<toCheck; k++) {
+ if(_values[k] != POIFSConstants.UNUSED_BLOCK) {
+ usedSectors ++;
+ }
+ }
+ return usedSectors;
+ }
public int getValueAt(int relativeOffset) {
if(relativeOffset >= _values.length) {