FileDocCategorySizeDatePackage
BlockListImpl.javaAPI DocApache Poi 3.0.14177Mon Jan 01 12:39:36 GMT 2007org.apache.poi.poifs.storage

BlockListImpl

public class BlockListImpl extends Object implements BlockList
A simple implementation of BlockList
author
Marc Johnson (mjohnson at apache dot org

Fields Summary
private ListManagedBlock[]
_blocks
private BlockAllocationTableReader
_bat
Constructors Summary
protected BlockListImpl()
Constructor BlockListImpl

        _blocks = new ListManagedBlock[ 0 ];
        _bat    = null;
    
Methods Summary
public org.apache.poi.poifs.storage.ListManagedBlock[]fetchBlocks(int startBlock)
get the blocks making up a particular stream in the list. The blocks are removed from the list.

param
startBlock the index of the first block in the stream
return
the stream as an array of correctly ordered blocks
exception
IOException if blocks are missing

        if (_bat == null)
        {
            throw new IOException(
                "Improperly initialized list: no block allocation table provided");
        }
        return _bat.fetchBlocks(startBlock, this);
    
public org.apache.poi.poifs.storage.ListManagedBlockremove(int index)
remove and return the specified block from the list

param
index the index of the specified block
return
the specified block
exception
IOException if the index is out of range or has already been removed

        ListManagedBlock result = null;

        try
        {
            result = _blocks[ index ];
            if (result == null)
            {
                throw new IOException("block[ " + index
                                      + " ] already removed");
            }
            _blocks[ index ] = null;
        }
        catch (ArrayIndexOutOfBoundsException ignored)
        {
            throw new IOException("Cannot remove block[ " + index
                                  + " ]; out of range");
        }
        return result;
    
public voidsetBAT(org.apache.poi.poifs.storage.BlockAllocationTableReader bat)
set the associated BlockAllocationTable

param
bat the associated BlockAllocationTable
exception
IOException

        if (_bat != null)
        {
            throw new IOException(
                "Attempt to replace existing BlockAllocationTable");
        }
        _bat = bat;
    
protected voidsetBlocks(org.apache.poi.poifs.storage.ListManagedBlock[] blocks)
provide blocks to manage

param
blocks blocks to be managed

        _blocks = blocks;
    
public voidzap(int index)
remove the specified block from the list

param
index the index of the specified block; if the index is out of range, that's ok

        if ((index >= 0) && (index < _blocks.length))
        {
            _blocks[ index ] = null;
        }