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

HeaderBlockWriter

public class HeaderBlockWriter extends BigBlock implements HeaderBlockConstants
The block containing the archive header
author
Marc Johnson (mjohnson at apache dot org)

Fields Summary
private static final byte
_default_value
private IntegerField
_bat_count
private IntegerField
_property_start
private IntegerField
_sbat_start
private IntegerField
_sbat_block_count
private IntegerField
_xbat_start
private IntegerField
_xbat_count
private byte[]
_data
Constructors Summary
public HeaderBlockWriter()
Create a single instance initialized with default values


                 

     
    
        _data = new byte[ POIFSConstants.BIG_BLOCK_SIZE ];
        Arrays.fill(_data, _default_value);
        new LongField(_signature_offset, _signature, _data);
        new IntegerField(0x08, 0, _data);
        new IntegerField(0x0c, 0, _data);
        new IntegerField(0x10, 0, _data);
        new IntegerField(0x14, 0, _data);
        new ShortField(0x18, ( short ) 0x3b, _data);
        new ShortField(0x1a, ( short ) 0x3, _data);
        new ShortField(0x1c, ( short ) -2, _data);
        new ShortField(0x1e, ( short ) 0x9, _data);
        new IntegerField(0x20, 0x6, _data);
        new IntegerField(0x24, 0, _data);
        new IntegerField(0x28, 0, _data);
        _bat_count      = new IntegerField(_bat_count_offset, 0, _data);
        _property_start = new IntegerField(_property_start_offset,
                                           POIFSConstants.END_OF_CHAIN,
                                           _data);
        new IntegerField(0x34, 0, _data);
        new IntegerField(0x38, 0x1000, _data);
        _sbat_start = new IntegerField(_sbat_start_offset,
                                       POIFSConstants.END_OF_CHAIN, _data);
        _sbat_block_count = new IntegerField(_sbat_block_count_offset, 0,
					     _data);
        _xbat_start = new IntegerField(_xbat_start_offset,
                                       POIFSConstants.END_OF_CHAIN, _data);
        _xbat_count = new IntegerField(_xbat_count_offset, 0, _data);
    
Methods Summary
static intcalculateXBATStorageRequirements(int blockCount)
For a given number of BAT blocks, calculate how many XBAT blocks will be needed

param
blockCount number of BAT blocks
return
number of XBAT blocks needed

        return (blockCount > _max_bats_in_header)
               ? BATBlock.calculateXBATStorageRequirements(blockCount
                   - _max_bats_in_header)
               : 0;
    
public org.apache.poi.poifs.storage.BATBlock[]setBATBlocks(int blockCount, int startBlock)
Set BAT block parameters. Assumes that all BAT blocks are contiguous. Will construct XBAT blocks if necessary and return the array of newly constructed XBAT blocks.

param
blockCount count of BAT blocks
param
startBlock index of first BAT block
return
array of XBAT blocks; may be zero length, will not be null

        BATBlock[] rvalue;

        _bat_count.set(blockCount, _data);
        int limit  = Math.min(blockCount, _max_bats_in_header);
        int offset = _bat_array_offset;

        for (int j = 0; j < limit; j++)
        {
            new IntegerField(offset, startBlock + j, _data);
            offset += LittleEndianConsts.INT_SIZE;
        }
        if (blockCount > _max_bats_in_header)
        {
            int   excess_blocks      = blockCount - _max_bats_in_header;
            int[] excess_block_array = new int[ excess_blocks ];

            for (int j = 0; j < excess_blocks; j++)
            {
                excess_block_array[ j ] = startBlock + j
                                          + _max_bats_in_header;
            }
            rvalue = BATBlock.createXBATBlocks(excess_block_array,
                                               startBlock + blockCount);
            _xbat_start.set(startBlock + blockCount, _data);
        }
        else
        {
            rvalue = BATBlock.createXBATBlocks(new int[ 0 ], 0);
            _xbat_start.set(POIFSConstants.END_OF_CHAIN, _data);
        }
        _xbat_count.set(rvalue.length, _data);
        return rvalue;
    
public voidsetPropertyStart(int startBlock)
Set start of Property Table

param
startBlock the index of the first block of the Property Table

        _property_start.set(startBlock, _data);
    
public voidsetSBATBlockCount(int count)
Set count of SBAT blocks

param
count the number of SBAT blocks

	_sbat_block_count.set(count, _data);
    
public voidsetSBATStart(int startBlock)
Set start of small block allocation table

param
startBlock the index of the first big block of the small block allocation table

        _sbat_start.set(startBlock, _data);
    
voidwriteData(java.io.OutputStream stream)
Write the block's data to an OutputStream

param
stream the OutputStream to which the stored data should be written
exception
IOException on problems writing to the specified stream

        doWriteData(stream, _data);