Top Description Inners Fields Constructors Methods
org.apache.poi.poifs.storage

public final Class BATBlock

extends Object
implements BlockWritable
Class Inheritance
All Implemented Interfaces
org.apache.poi.poifs.storage.BlockWritable
Imports
java.io.IOException, .OutputStream, java.nio.ByteBuffer, java.util.Arrays, .List, org.apache.poi.poifs.common.POIFSBigBlockSize, .POIFSConstants, org.apache.poi.util.LittleEndian, .LittleEndianConsts

A block of block allocation table entries. BATBlocks are created only through a static factory method: createBATBlocks.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class

Field Summary

Modifier and TypeField and Description
private boolean
_has_free_sectors

Does this BATBlock have any free sectors in it?

private int[]
_values

For a regular fat block, these are 128 / 1024 next sector values.

private POIFSBigBlockSize
private int
ourBlockIndex

Where in the file are we?

Constructor Summary

AccessConstructor and Description
private
BATBlock(POIFSBigBlockSize bigBlockSize)

Create a single instance initialized with default values

Method Summary

Modifier and TypeMethod and Description
public static long
calculateMaximumSize(final POIFSBigBlockSize bigBlockSize, final int numBATs)

Calculates the maximum size of a file which is addressable given the number of FAT (BAT) sectors specified.

public static long
public static BATBlock
createBATBlock(final 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.

public static BATBlock
createEmptyBATBlock(final POIFSBigBlockSize bigBlockSize, boolean isXBAT)

Creates a single BATBlock, with all the values set to empty.

public static BATBlock.BATBlockAndIndex
getBATBlockAndIndex(final int offset, final HeaderBlock header, final List<BATBlock> bats)

Returns the BATBlock that handles the specified offset, and the relative index within it.

public int
getOccupiedSize()

How much of this block is occupied?.

public int
getOurBlockIndex()

Retrieve where in the file we live

public static BATBlock.BATBlockAndIndex
getSBATBlockAndIndex(final int offset, final HeaderBlock header, final List<BATBlock> sbats)

Returns the BATBlock that handles the specified offset, and the relative index within it, for the mini stream.

public int
getUsedSectors(boolean isAnXBAT)

How many sectors in this block are taken?

public int
getValueAt(int relativeOffset)

public boolean
hasFreeSectors()

Does this BATBlock have any free sectors in it, or is it full?

private void
private byte[]
public void
setOurBlockIndex(int index)

Record where in the file we live

public void
setValueAt(int relativeOffset, int value)

public void
writeBlocks(final OutputStream
the OutputStream to which the stored data should be written
stream
)

Implements org.apache.poi.poifs.storage.BlockWritable.writeBlocks.

Write the block's data to an OutputStream

public void
writeData(final ByteBuffer block)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

_has_free_sectorsback to summary
private boolean _has_free_sectors

Does this BATBlock have any free sectors in it?

_valuesback to summary
private int[] _values

For 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.

bigBlockSizeback to summary
private POIFSBigBlockSize bigBlockSize

Either 512 bytes (POIFSConstants#SMALLER_BIG_BLOCK_SIZE) or 4096 bytes (POIFSConstants#LARGER_BIG_BLOCK_SIZE)

ourBlockIndexback to summary
private int ourBlockIndex

Where in the file are we?

Constructor Detail

BATBlockback to summary
private BATBlock(POIFSBigBlockSize bigBlockSize)

Create a single instance initialized with default values

Method Detail

calculateMaximumSizeback to summary
public static long calculateMaximumSize(final POIFSBigBlockSize bigBlockSize, final 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

calculateMaximumSizeback to summary
public static long calculateMaximumSize(final HeaderBlock header)
createBATBlockback to summary
public static BATBlock createBATBlock(final 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.

createEmptyBATBlockback to summary
public static BATBlock createEmptyBATBlock(final POIFSBigBlockSize bigBlockSize, boolean isXBAT)

Creates a single BATBlock, with all the values set to empty.

getBATBlockAndIndexback to summary
public static BATBlock.BATBlockAndIndex getBATBlockAndIndex(final int offset, final HeaderBlock header, final 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

getOccupiedSizeback to summary
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
getOurBlockIndexback to summary
public int getOurBlockIndex()

Retrieve where in the file we live

getSBATBlockAndIndexback to summary
public static BATBlock.BATBlockAndIndex getSBATBlockAndIndex(final int offset, final HeaderBlock header, final 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

getUsedSectorsback to summary
public int getUsedSectors(boolean isAnXBAT)

How many sectors in this block are taken? Note that calling hasFreeSectors() is much quicker

getValueAtback to summary
public int getValueAt(int relativeOffset)
hasFreeSectorsback to summary
public boolean hasFreeSectors()

Does this BATBlock have any free sectors in it, or is it full?

recomputeFreeback to summary
private void recomputeFree()
serializeback to summary
private byte[] serialize()
setOurBlockIndexback to summary
public void setOurBlockIndex(int index)

Record where in the file we live

setValueAtback to summary
public void setValueAt(int relativeOffset, int value)
writeBlocksback to summary
public void writeBlocks(final OutputStream stream) throws IOException

Implements org.apache.poi.poifs.storage.BlockWritable.writeBlocks.

Write the block's data to an OutputStream

Parameters
stream:OutputStream

the OutputStream to which the stored data should be written

Exceptions
IOException:
on problems writing to the specified stream
writeDataback to summary
public void writeData(final ByteBuffer block)
org.apache.poi.poifs.storage back to summary

public final Class BATBlock.BATBlockAndIndex

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final BATBlock
private final int

Constructor Summary

AccessConstructor and Description
private
BATBlockAndIndex(int index, BATBlock block)

Method Summary

Modifier and TypeMethod and Description
public BATBlock
public int
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

blockback to summary
private final BATBlock block
indexback to summary
private final int index

Constructor Detail

BATBlockAndIndexback to summary
private BATBlockAndIndex(int index, BATBlock block)

Method Detail

getBlockback to summary
public BATBlock getBlock()
getIndexback to summary
public int getIndex()