Class BATBlock

java.lang.Object
org.apache.poi.poifs.storage.BATBlock
All Implemented Interfaces:
BlockWritable

public final class BATBlock extends Object implements BlockWritable
A block of block allocation table entries. BATBlocks are created only through a static factory method: createBATBlocks.
  • Method Details

    • createBATBlock

      public static BATBlock createBATBlock(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.
    • createEmptyBATBlock

      public static BATBlock createEmptyBATBlock(POIFSBigBlockSize bigBlockSize, boolean isXBAT)
      Creates a single BATBlock, with all the values set to empty.
    • calculateMaximumSize

      public static long calculateMaximumSize(POIFSBigBlockSize bigBlockSize, int numBATs)
      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

      public static long calculateMaximumSize(HeaderBlock header)
    • 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
    • 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 calling hasFreeSectors() is much quicker
    • getOccupiedSize

      public int getOccupiedSize()
      How much of this block is occupied?. This counts the number of sectors up and including the last used sector. Note that this is different from getUsedSectors(boolean) which could be smaller as it does not count unused sectors where there are used ones after it (i.e. fragmentation).
      Since:
      POI 5.0.0
    • 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
    • writeBlocks

      public void writeBlocks(OutputStream stream) throws IOException
      Write the block's data to an OutputStream
      Specified by:
      writeBlocks in interface BlockWritable
      Parameters:
      stream - the OutputStream to which the stored data should be written
      Throws:
      IOException - on problems writing to the specified stream
    • writeData

      public void writeData(ByteBuffer block)