org.apache.poi.poifs.storage
Class BlockAllocationTableWriter

java.lang.Object
  extended by org.apache.poi.poifs.storage.BlockAllocationTableWriter
All Implemented Interfaces:
BATManaged, BlockWritable

public final class BlockAllocationTableWriter
extends java.lang.Object
implements BlockWritable, BATManaged

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.


Constructor Summary
BlockAllocationTableWriter(POIFSBigBlockSize bigBlockSize)
          create a BlockAllocationTableWriter
 
Method Summary
 int allocateSpace(int blockCount)
          Allocate space for a block of indices
 int countBlocks()
          Return the number of BigBlock's this instance uses
 int createBlocks()
          Create the BATBlocks we need
 int getStartBlock()
          get the starting block
 void setStartBlock(int start_block)
          Set the start block for this instance
static void writeBlock(BATBlock bat, java.nio.ByteBuffer block)
          Write the BAT into its associated block
 void writeBlocks(java.io.OutputStream stream)
          Write the storage to an OutputStream
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BlockAllocationTableWriter

public BlockAllocationTableWriter(POIFSBigBlockSize bigBlockSize)
create a BlockAllocationTableWriter

Method Detail

createBlocks

public int createBlocks()
Create the BATBlocks we need

Returns:
start block index of BAT blocks

allocateSpace

public int allocateSpace(int blockCount)
Allocate space for a block of indices

Parameters:
blockCount - the number of blocks to allocate space for
Returns:
the starting index of the blocks

getStartBlock

public int getStartBlock()
get the starting block

Returns:
the starting block index

writeBlocks

public void writeBlocks(java.io.OutputStream stream)
                 throws java.io.IOException
Write the storage to an OutputStream

Specified by:
writeBlocks in interface BlockWritable
Parameters:
stream - the OutputStream to which the stored data should be written
Throws:
java.io.IOException - on problems writing to the specified stream

writeBlock

public static void writeBlock(BATBlock bat,
                              java.nio.ByteBuffer block)
                       throws java.io.IOException
Write the BAT into its associated block

Throws:
java.io.IOException

countBlocks

public int countBlocks()
Return the number of BigBlock's this instance uses

Specified by:
countBlocks in interface BATManaged
Returns:
count of BigBlock instances

setStartBlock

public void setStartBlock(int start_block)
Set the start block for this instance

Specified by:
setStartBlock in interface BATManaged
Parameters:
start_block - index into the array of BigBlock instances making up the the filesystem