Class BATBlock
java.lang.Object
org.docx4j.org.apache.poi.poifs.storage.BigBlock
org.docx4j.org.apache.poi.poifs.storage.BATBlock
- All Implemented Interfaces:
BlockWritable
A block of block allocation table entries. BATBlocks are created
only through a static factory method: createBATBlocks.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate booleanDoes this BATBlock have any free sectors in it?private int[]For a regular fat block, these are 128 / 1024 next sector values.private intWhere in the file are we?Fields inherited from class org.docx4j.org.apache.poi.poifs.storage.BigBlock
bigBlockSize -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateBATBlock(POIFSBigBlockSize bigBlockSize) Create a single instance initialized with default valuesprivateBATBlock(POIFSBigBlockSize bigBlockSize, int[] entries, int start_index, int end_index) Create a single instance initialized (perhaps partially) with entries -
Method Summary
Modifier and TypeMethodDescriptionstatic longcalculateMaximumSize(POIFSBigBlockSize bigBlockSize, int numBATs) Calculates the maximum size of a file which is addressable given the number of FAT (BAT) sectors specified.static longcalculateMaximumSize(HeaderBlock header) static intcalculateStorageRequirements(POIFSBigBlockSize bigBlockSize, int entryCount) Calculate how many BATBlocks are needed to hold a specified number of BAT entries.static intcalculateXBATStorageRequirements(POIFSBigBlockSize bigBlockSize, int entryCount) Calculate how many XBATBlocks are needed to hold a specified number of BAT entries.static BATBlockcreateBATBlock(POIFSBigBlockSize bigBlockSize, ByteBuffer data) Create a single BATBlock from the byte buffer, which must hold at least one big block of data to be read.static BATBlock[]createBATBlocks(POIFSBigBlockSize bigBlockSize, int[] entries) Create an array of BATBlocks from an array of int block allocation table entriesstatic BATBlockcreateEmptyBATBlock(POIFSBigBlockSize bigBlockSize, boolean isXBAT) Creates a single BATBlock, with all the values set to empty.static BATBlock[]createXBATBlocks(POIFSBigBlockSize bigBlockSize, int[] entries, int startBlock) Create an array of XBATBlocks from an array of int block allocation table entriesstatic BATBlock.BATBlockAndIndexgetBATBlockAndIndex(int offset, HeaderBlock header, List<BATBlock> bats) Returns the BATBlock that handles the specified offset, and the relative index within it.intRetrieve where in the file we livestatic BATBlock.BATBlockAndIndexgetSBATBlockAndIndex(int offset, HeaderBlock header, List<BATBlock> sbats) Returns the BATBlock that handles the specified offset, and the relative index within it, for the mini stream.intgetUsedSectors(boolean isAnXBAT) How many sectors in this block are taken? Note that callinghasFreeSectors()is much quickerintgetValueAt(int relativeOffset) booleanDoes this BATBlock have any free sectors in it, or is it full?private voidprivate byte[]voidsetOurBlockIndex(int index) Record where in the file we livevoidsetValueAt(int relativeOffset, int value) private voidsetXBATChain(POIFSBigBlockSize bigBlockSize, int chainIndex) (package private) voidwriteData(OutputStream stream) Write the block's data to an OutputStream(package private) voidwriteData(ByteBuffer block) Methods inherited from class org.docx4j.org.apache.poi.poifs.storage.BigBlock
doWriteData, writeBlocks
-
Field Details
-
_values
private int[] _valuesFor a regular fat block, these are 128 / 1024 next sector values. For a XFat (DIFat) block, these are 127 / 1023 next sector values, then a chaining value. -
_has_free_sectors
private boolean _has_free_sectorsDoes this BATBlock have any free sectors in it? -
ourBlockIndex
private int ourBlockIndexWhere in the file are we?
-
-
Constructor Details
-
BATBlock
Create a single instance initialized with default values -
BATBlock
Create a single instance initialized (perhaps partially) with entries- Parameters:
entries- the array of block allocation table entriesstart_index- the index of the first entry to be written to the blockend_index- the index, plus one, of the last entry to be written to the block (writing is for all index k, start_index <= k < end_index)
-
-
Method Details
-
recomputeFree
private void recomputeFree() -
createBATBlock
Create a single BATBlock from the byte buffer, which must hold at least one big block of data to be read. -
createEmptyBATBlock
Creates a single BATBlock, with all the values set to empty. -
createBATBlocks
Create an array of BATBlocks from an array of int block allocation table entries- Parameters:
entries- the array of int entries- Returns:
- the newly created array of BATBlocks
-
createXBATBlocks
public static BATBlock[] createXBATBlocks(POIFSBigBlockSize bigBlockSize, int[] entries, int startBlock) Create an array of XBATBlocks from an array of int block allocation table entries- Parameters:
entries- the array of int entriesstartBlock- the start block of the array of XBAT blocks- Returns:
- the newly created array of BATBlocks
-
calculateStorageRequirements
Calculate how many BATBlocks are needed to hold a specified number of BAT entries.- Parameters:
entryCount- the number of entries- Returns:
- the number of BATBlocks needed
-
calculateXBATStorageRequirements
Calculate how many XBATBlocks are needed to hold a specified number of BAT entries.- Parameters:
entryCount- the number of entries- Returns:
- the number of XBATBlocks needed
-
calculateMaximumSize
Calculates the maximum size of a file which is addressable given the number of FAT (BAT) sectors specified. (We don't care if those BAT blocks come from the 109 in the header, or from header + XBATS, it won't affect the calculation) The actual file size will be between [size of fatCount-1 blocks] and [size of fatCount blocks]. For 512 byte block sizes, this means we may over-estimate by up to 65kb. For 4096 byte block sizes, this means we may over-estimate by up to 4mb -
calculateMaximumSize
-
getBATBlockAndIndex
public static BATBlock.BATBlockAndIndex getBATBlockAndIndex(int offset, HeaderBlock header, List<BATBlock> bats) Returns the BATBlock that handles the specified offset, and the relative index within it. The List of BATBlocks must be in sequential order -
getSBATBlockAndIndex
public static BATBlock.BATBlockAndIndex getSBATBlockAndIndex(int offset, HeaderBlock header, List<BATBlock> sbats) Returns the BATBlock that handles the specified offset, and the relative index within it, for the mini stream. The List of BATBlocks must be in sequential order -
setXBATChain
-
hasFreeSectors
public boolean hasFreeSectors()Does this BATBlock have any free sectors in it, or is it full? -
getUsedSectors
public int getUsedSectors(boolean isAnXBAT) How many sectors in this block are taken? Note that callinghasFreeSectors()is much quicker -
getValueAt
public int getValueAt(int relativeOffset) -
setValueAt
public void setValueAt(int relativeOffset, int value) -
setOurBlockIndex
public void setOurBlockIndex(int index) Record where in the file we live -
getOurBlockIndex
public int getOurBlockIndex()Retrieve where in the file we live -
writeData
Write the block's data to an OutputStream- Specified by:
writeDatain classBigBlock- Parameters:
stream- the OutputStream to which the stored data should be written- Throws:
IOException- on problems writing to the specified stream
-
writeData
- Throws:
IOException
-
serialize
private byte[] serialize()
-