org.apache.poi.poifs.storage
Class SmallDocumentBlock

java.lang.Object
  extended by org.apache.poi.poifs.storage.SmallDocumentBlock
All Implemented Interfaces:
BlockWritable, ListManagedBlock

public final class SmallDocumentBlock
extends java.lang.Object
implements BlockWritable, ListManagedBlock

Storage for documents that are too small to use regular DocumentBlocks for their data


Constructor Summary
protected SmallDocumentBlock(POIFSBigBlockSize bigBlockSize)
           
 
Method Summary
static int calcSize(int size)
          Calculate the storage size of a set of SmallDocumentBlocks
static SmallDocumentBlock[] convert(POIFSBigBlockSize bigBlockSize, BlockWritable[] store, int size)
          Factory for creating SmallDocumentBlocks from DocumentBlocks
static SmallDocumentBlock[] convert(POIFSBigBlockSize bigBlockSize, byte[] array, int size)
          convert a single long array into an array of SmallDocumentBlock instances
static java.util.List<SmallDocumentBlock> extract(POIFSBigBlockSize bigBlockSize, ListManagedBlock[] blocks)
          create a list of SmallDocumentBlock's from raw data
static int fill(POIFSBigBlockSize bigBlockSize, java.util.List<SmallDocumentBlock> blocks)
          fill out a List of SmallDocumentBlocks so that it fully occupies a set of big blocks
 POIFSBigBlockSize getBigBlockSize()
           
 byte[] getData()
          Get the data from the block
static DataInputBlock getDataInputBlock(SmallDocumentBlock[] blocks, int offset)
           
protected  int getSmallBlocksPerBigBlock()
           
 void writeBlocks(java.io.OutputStream stream)
          Write the storage to an OutputStream
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SmallDocumentBlock

protected SmallDocumentBlock(POIFSBigBlockSize bigBlockSize)
Method Detail

convert

public static SmallDocumentBlock[] convert(POIFSBigBlockSize bigBlockSize,
                                           byte[] array,
                                           int size)
convert a single long array into an array of SmallDocumentBlock instances

Parameters:
array - the byte array to be converted
size - the intended size of the array (which may be smaller)
Returns:
an array of SmallDocumentBlock instances, filled from the array

fill

public static int fill(POIFSBigBlockSize bigBlockSize,
                       java.util.List<SmallDocumentBlock> blocks)
fill out a List of SmallDocumentBlocks so that it fully occupies a set of big blocks

Parameters:
blocks - the List to be filled out
Returns:
number of big blocks the list encompasses

convert

public static SmallDocumentBlock[] convert(POIFSBigBlockSize bigBlockSize,
                                           BlockWritable[] store,
                                           int size)
                                    throws java.io.IOException,
                                           java.lang.ArrayIndexOutOfBoundsException
Factory for creating SmallDocumentBlocks from DocumentBlocks

Parameters:
store - the original DocumentBlocks
size - the total document size
Returns:
an array of new SmallDocumentBlocks instances
Throws:
java.io.IOException - on errors reading from the DocumentBlocks
java.lang.ArrayIndexOutOfBoundsException - if, somehow, the store contains less data than size indicates

extract

public static java.util.List<SmallDocumentBlock> extract(POIFSBigBlockSize bigBlockSize,
                                                         ListManagedBlock[] blocks)
                                                  throws java.io.IOException
create a list of SmallDocumentBlock's from raw data

Parameters:
blocks - the raw data containing the SmallDocumentBlock data
Returns:
a List of SmallDocumentBlock's extracted from the input
Throws:
java.io.IOException

getDataInputBlock

public static DataInputBlock getDataInputBlock(SmallDocumentBlock[] blocks,
                                               int offset)

calcSize

public static int calcSize(int size)
Calculate the storage size of a set of SmallDocumentBlocks

Parameters:
size - number of SmallDocumentBlocks
Returns:
total size

getSmallBlocksPerBigBlock

protected int getSmallBlocksPerBigBlock()

writeBlocks

public void writeBlocks(java.io.OutputStream stream)
                 throws java.io.IOException
Write the storage to an OutputStream

Specified by:
writeBlocks in interface BlockWritable
Parameters:
stream - the OutputStream to which the stored data should be written
Throws:
java.io.IOException - on problems writing to the specified stream

getData

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

Specified by:
getData in interface ListManagedBlock
Returns:
the block's data as a byte array
Throws:
java.io.IOException - if there is no data

getBigBlockSize

public POIFSBigBlockSize getBigBlockSize()