FileDocCategorySizeDatePackage
LocalRawDataBlockList.javaAPI DocApache Poi 3.0.15302Mon Jan 01 12:39:44 GMT 2007org.apache.poi.poifs.storage

LocalRawDataBlockList

public class LocalRawDataBlockList extends RawDataBlockList
Class LocalRawDataBlockList
author
Marc Johnson(mjohnson at apache dot org)

Fields Summary
private List
_list
private RawDataBlock[]
_array
Constructors Summary
public LocalRawDataBlockList()
Constructor LocalRawDataBlockList

exception
IOException

        super(new ByteArrayInputStream(new byte[ 0 ]));
        _list  = new ArrayList();
        _array = null;
    
Methods Summary
public voidadd(org.apache.poi.poifs.storage.RawDataBlock block)
add a new block

param
block new block to add

        _list.add(block);
    
public voidcreateNewBATBlock(int start_index)
create a BAT block and add it to the list

param
start_index initial index for the block list
exception
IOException

        byte[] data   = new byte[ 512 ];
        int    offset = 0;

        for (int j = 0; j < 128; j++)
        {
            int index = start_index + j;

            if (index % 256 == 0)
            {
                LittleEndian.putInt(data, offset, -1);
            }
            else if (index % 256 == 255)
            {
                LittleEndian.putInt(data, offset, -2);
            }
            else
            {
                LittleEndian.putInt(data, offset, index + 1);
            }
            offset += LittleEndianConsts.INT_SIZE;
        }
        add(new RawDataBlock(new ByteArrayInputStream(data)));
    
public voidcreateNewXBATBlock(int start, int end, int chain)
create and a new XBAT block

param
start index of first BAT block
param
end index of last BAT block
param
chain index of next XBAT block
exception
IOException

        byte[] data   = new byte[ 512 ];
        int    offset = 0;

        for (int k = start; k <= end; k++)
        {
            LittleEndian.putInt(data, offset, k);
            offset += LittleEndianConsts.INT_SIZE;
        }
        while (offset != 508)
        {
            LittleEndian.putInt(data, offset, -1);
            offset += LittleEndianConsts.INT_SIZE;
        }
        LittleEndian.putInt(data, offset, chain);
        add(new RawDataBlock(new ByteArrayInputStream(data)));
    
private voidensureArrayExists()

        if (_array == null)
        {
            _array = ( RawDataBlock [] ) _list.toArray(new RawDataBlock[ 0 ]);
        }
    
public voidfill(int count)
fill the list with dummy blocks

param
count of blocks
exception
IOException

        int limit = 128 * count;

        for (int j = _list.size(); j < limit; j++)
        {
            add(new RawDataBlock(new ByteArrayInputStream(new byte[ 0 ])));
        }
    
public org.apache.poi.poifs.storage.ListManagedBlockremove(int index)
override of remove method

param
index of block to be removed
return
desired block
exception
IOException

        ensureArrayExists();
        RawDataBlock rvalue = null;

        try
        {
            rvalue = _array[ index ];
            if (rvalue == null)
            {
                throw new IOException("index " + index + " is null");
            }
            _array[ index ] = null;
        }
        catch (ArrayIndexOutOfBoundsException ignored)
        {
            throw new IOException("Cannot remove block[ " + index
                                  + " ]; out of range");
        }
        return rvalue;
    
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

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