FileDocCategorySizeDatePackage
HeaderBlockReader.javaAPI DocApache Poi 3.0.15252Thu May 31 18:44:06 BST 2007org.apache.poi.poifs.storage

HeaderBlockReader

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

Fields Summary
private IntegerField
_bat_count
private IntegerField
_property_start
private IntegerField
_sbat_start
private IntegerField
_xbat_start
private IntegerField
_xbat_count
private byte[]
_data
Constructors Summary
public HeaderBlockReader(InputStream stream)
create a new HeaderBlockReader from an InputStream

param
stream the source InputStream
exception
IOException on errors or bad data

        _data = new byte[ POIFSConstants.BIG_BLOCK_SIZE ];
        int byte_count = IOUtils.readFully(stream, _data);

        if (byte_count != POIFSConstants.BIG_BLOCK_SIZE)
        {
        	if (byte_count == -1)
        		//Cant have -1 bytes read in the error message!
        		byte_count = 0;
            String type = " byte" + ((byte_count == 1) ? ("")
                                                       : ("s"));

            throw new IOException("Unable to read entire header; "
                                  + byte_count + type + " read; expected "
                                  + POIFSConstants.BIG_BLOCK_SIZE + " bytes");
        }

        // verify signature
        LongField signature = new LongField(_signature_offset, _data);

        if (signature.get() != _signature)
        {
			// Is it one of the usual suspects?
			if(_data[0] == 0x50 && _data[1] == 0x4b && _data[2] == 0x03 &&
					_data[3] == 0x04) {
				throw new OfficeXmlFileException("The supplied data appears to be in the Office 2007+ XML. POI only supports OLE2 Office documents");
			}

			// Give a generic error
            throw new IOException("Invalid header signature; read "
                                  + signature.get() + ", expected "
                                  + _signature);
        }
        _bat_count      = new IntegerField(_bat_count_offset, _data);
        _property_start = new IntegerField(_property_start_offset, _data);
        _sbat_start     = new IntegerField(_sbat_start_offset, _data);
        _xbat_start     = new IntegerField(_xbat_start_offset, _data);
        _xbat_count     = new IntegerField(_xbat_count_offset, _data);
    
Methods Summary
public int[]getBATArray()

return
BAT array

        int[] result = new int[ _max_bats_in_header ];
        int   offset = _bat_array_offset;

        for (int j = 0; j < _max_bats_in_header; j++)
        {
            result[ j ] = LittleEndian.getInt(_data, offset);
            offset      += LittleEndianConsts.INT_SIZE;
        }
        return result;
    
public intgetBATCount()

return
number of BAT blocks

        return _bat_count.get();
    
public intgetPropertyStart()
get start of Property Table

return
the index of the first block of the Property Table

        return _property_start.get();
    
public intgetSBATStart()

return
start of small block allocation table

        return _sbat_start.get();
    
public intgetXBATCount()

return
XBAT count

        return _xbat_count.get();
    
public intgetXBATIndex()

return
XBAT index

        return _xbat_start.get();