POIFSDocumentpublic class POIFSDocument extends Object implements BlockWritable, POIFSViewable, BATManagedThis class manages a document in the POIFS filesystem. |
Fields Summary |
---|
private DocumentProperty | _property | private int | _size | private SmallBlockStore | _small_store | private BigBlockStore | _big_store |
Constructors Summary |
---|
public POIFSDocument(String name, RawDataBlock[] blocks, int length)Constructor from large blocks
_size = length;
_big_store = new BigBlockStore(blocks);
_property = new DocumentProperty(name, _size);
_small_store = new SmallBlockStore(new BlockWritable[ 0 ]);
_property.setDocument(this);
| public POIFSDocument(String name, SmallDocumentBlock[] blocks, int length)Constructor from small blocks
_size = length;
try
{
_big_store = new BigBlockStore(new RawDataBlock[ 0 ]);
}
catch (IOException ignored)
{
// can't happen with that constructor
}
_property = new DocumentProperty(name, _size);
_small_store = new SmallBlockStore(blocks);
_property.setDocument(this);
| public POIFSDocument(String name, ListManagedBlock[] blocks, int length)Constructor from small blocks
_size = length;
_property = new DocumentProperty(name, _size);
_property.setDocument(this);
if (Property.isSmall(_size))
{
_big_store = new BigBlockStore(new RawDataBlock[ 0 ]);
_small_store = new SmallBlockStore(blocks);
}
else
{
_big_store = new BigBlockStore(blocks);
_small_store = new SmallBlockStore(new BlockWritable[ 0 ]);
}
| public POIFSDocument(String name, InputStream stream)Constructor
List blocks = new ArrayList();
_size = 0;
while (true)
{
DocumentBlock block = new DocumentBlock(stream);
int blockSize = block.size();
if (blockSize > 0)
{
blocks.add(block);
_size += blockSize;
}
if (block.partiallyRead())
{
break;
}
}
DocumentBlock[] bigBlocks =
( DocumentBlock [] ) blocks.toArray(new DocumentBlock[ 0 ]);
_big_store = new BigBlockStore(bigBlocks);
_property = new DocumentProperty(name, _size);
_property.setDocument(this);
if (_property.shouldUseSmallBlocks())
{
_small_store =
new SmallBlockStore(SmallDocumentBlock.convert(bigBlocks,
_size));
_big_store = new BigBlockStore(new DocumentBlock[ 0 ]);
}
else
{
_small_store = new SmallBlockStore(new BlockWritable[ 0 ]);
}
| public POIFSDocument(String name, int size, POIFSDocumentPath path, POIFSWriterListener writer)Constructor
_size = size;
_property = new DocumentProperty(name, _size);
_property.setDocument(this);
if (_property.shouldUseSmallBlocks())
{
_small_store = new SmallBlockStore(path, name, size, writer);
_big_store = new BigBlockStore(new Object[ 0 ]);
}
else
{
_small_store = new SmallBlockStore(new BlockWritable[ 0 ]);
_big_store = new BigBlockStore(path, name, size, writer);
}
|
Methods Summary |
---|
public int | countBlocks()Return the number of BigBlock's this instance uses
return _big_store.countBlocks();
| org.apache.poi.poifs.property.DocumentProperty | getDocumentProperty()Get the DocumentProperty
return _property;
| public java.lang.String | getShortDescription()Provides a short description of the object, to be used when a
POIFSViewable object has not provided its contents.
StringBuffer buffer = new StringBuffer();
buffer.append("Document: \"").append(_property.getName())
.append("\"");
buffer.append(" size = ").append(getSize());
return buffer.toString();
| public int | getSize()
return _size;
| public org.apache.poi.poifs.storage.BlockWritable[] | getSmallBlocks()return the array of SmallDocumentBlocks used
return _small_store.getBlocks();
| public java.lang.Object[] | getViewableArray()Get an array of objects, some of which may implement
POIFSViewable
Object[] results = new Object[ 1 ];
String result;
try
{
ByteArrayOutputStream output = new ByteArrayOutputStream();
BlockWritable[] blocks = null;
if (_big_store.isValid())
{
blocks = _big_store.getBlocks();
}
else if (_small_store.isValid())
{
blocks = _small_store.getBlocks();
}
if (blocks != null)
{
for (int k = 0; k < blocks.length; k++)
{
blocks[ k ].writeBlocks(output);
}
byte[] data = output.toByteArray();
if (data.length > _property.getSize())
{
byte[] tmp = new byte[ _property.getSize() ];
System.arraycopy(data, 0, tmp, 0, tmp.length);
data = tmp;
}
output = new ByteArrayOutputStream();
HexDump.dump(data, 0, output, 0);
result = output.toString();
}
else
{
result = "<NO DATA>";
}
}
catch (IOException e)
{
result = e.getMessage();
}
results[ 0 ] = result;
return results;
| public java.util.Iterator | getViewableIterator()Get an Iterator of objects, some of which may implement
POIFSViewable
return Collections.EMPTY_LIST.iterator();
| public boolean | preferArray()Give viewers a hint as to whether to call getViewableArray or
getViewableIterator
return true;
| void | read(byte[] buffer, int offset)read data from the internal stores
if (_property.shouldUseSmallBlocks())
{
SmallDocumentBlock.read(_small_store.getBlocks(), buffer, offset);
}
else
{
DocumentBlock.read(_big_store.getBlocks(), buffer, offset);
}
| public void | setStartBlock(int index)Set the start block for this instance
_property.setStartBlock(index);
| public void | writeBlocks(java.io.OutputStream stream)Write the storage to an OutputStream
_big_store.writeBlocks(stream);
|
|