Class BlockAllocationTableReader

java.lang.Object
org.docx4j.org.apache.poi.poifs.storage.BlockAllocationTableReader

public final class BlockAllocationTableReader extends Object
This class manages and creates the Block Allocation Table, which is basically a set of linked lists of block indices.

Each block of the filesystem has an index. The first block, the header, is skipped; the first block after the header is index 0, the next is index 1, and so on.

A block's index is also its index into the Block Allocation Table. The entry that it finds in the Block Allocation Table is the index of the next block in the linked list of blocks making up a file, or it is set to -2: end of list.

  • Field Details

    • _logger

      private static org.slf4j.Logger _logger
    • MAX_BLOCK_COUNT

      private static final int MAX_BLOCK_COUNT
      Maximum number size (in blocks) of the allocation table as supported by POI.
      This constant has been chosen to help POI identify corrupted data in the header block (rather than crash immediately with OutOfMemoryError ). It's not clear if the compound document format actually specifies any upper limits. For files with 512 byte blocks, having an allocation table of 65,335 blocks would correspond to a total file size of 4GB. Needless to say, POI probably cannot handle files anywhere near that size.
      See Also:
    • _entries

      private final IntList _entries
    • bigBlockSize

      private POIFSBigBlockSize bigBlockSize
  • Constructor Details

    • BlockAllocationTableReader

      public BlockAllocationTableReader(POIFSBigBlockSize bigBlockSize, int block_count, int[] block_array, int xbat_count, int xbat_index, BlockList raw_block_list) throws IOException
      create a BlockAllocationTableReader for an existing filesystem. Side effect: when this method finishes, the BAT blocks will have been removed from the raw block list, and any blocks labeled as 'unused' in the block allocation table will also have been removed from the raw block list.
      Parameters:
      block_count - the number of BAT blocks making up the block allocation table
      block_array - the array of BAT block indices from the filesystem's header
      xbat_count - the number of XBAT blocks
      xbat_index - the index of the first XBAT block
      raw_block_list - the list of RawDataBlocks
      Throws:
      IOException - if, in trying to create the table, we encounter logic errors
    • BlockAllocationTableReader

      BlockAllocationTableReader(POIFSBigBlockSize bigBlockSize, ListManagedBlock[] blocks, BlockList raw_block_list) throws IOException
      create a BlockAllocationTableReader from an array of raw data blocks
      Parameters:
      blocks - the raw data
      raw_block_list - the list holding the managed blocks
      Throws:
      IOException
    • BlockAllocationTableReader

      BlockAllocationTableReader(POIFSBigBlockSize bigBlockSize)
  • Method Details

    • sanityCheckBlockCount

      public static void sanityCheckBlockCount(int block_count) throws IOException
      Throws:
      IOException
    • fetchBlocks

      ListManagedBlock[] fetchBlocks(int startBlock, int headerPropertiesStartBlock, BlockList blockList) throws IOException
      walk the entries from a specified point and return the associated blocks. The associated blocks are removed from the block list
      Parameters:
      startBlock - the first block in the chain
      blockList - the raw data block list
      Returns:
      array of ListManagedBlocks, in their correct order
      Throws:
      IOException - if there is a problem acquiring the blocks
    • isUsed

      boolean isUsed(int index)
      determine whether the block specified by index is used or not
      Parameters:
      index - index of block in question
      Returns:
      true if the specific block is used, else false
    • getNextBlockIndex

      int getNextBlockIndex(int index) throws IOException
      return the next block index
      Parameters:
      index - of the current block
      Returns:
      index of the next block (may be POIFSConstants.END_OF_CHAIN, indicating end of chain (duh))
      Throws:
      IOException - if the current block is unused
    • setEntries

      private void setEntries(ListManagedBlock[] blocks, BlockList raw_blocks) throws IOException
      Convert an array of blocks into a set of integer indices
      Parameters:
      blocks - the array of blocks containing the indices
      raw_blocks - the list of blocks being managed. Unused blocks will be eliminated from the list
      Throws:
      IOException