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

RawDataBlock

public class RawDataBlock extends Object implements ListManagedBlock
A big block created from an InputStream, holding the raw data
author
Marc Johnson (mjohnson at apache dot org

Fields Summary
private byte[]
_data
private boolean
_eof
Constructors Summary
public RawDataBlock(InputStream stream)
Constructor RawDataBlock

param
stream the InputStream from which the data will be read
exception
IOException on I/O errors, and if an insufficient amount of data is read

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

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

            throw new IOException("Unable to read entire block; " + count
                                  + type + " read; expected "
                                  + POIFSConstants.BIG_BLOCK_SIZE + " bytes");
        }
        else
        {
            _eof = false;
        }
    
Methods Summary
public booleaneof()
When we read the data, did we hit end of file?

return
true if no data was read because we were at the end of the file, else false
exception
IOException

        return _eof;
    
public byte[]getData()
Get the data from the block

return
the block's data as a byte array
exception
IOException if there is no data

        if (eof())
        {
            throw new IOException("Cannot return empty data");
        }
        return _data;