This class manages a document in the POIFS filesystem.
| Constructor: |
public POIFSDocument(String name,
InputStream stream) throws IOException {
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 ]);
}
}
Parameters:
name - the name of the POIFSDocument
stream - the InputStream we read data from
Throws:
IOException - thrown on read errors
- exception:
IOException - thrown on read errors
|
public POIFSDocument(String name,
RawDataBlock[] blocks,
int length) throws IOException {
_size = length;
_big_store = new BigBlockStore(blocks);
_property = new DocumentProperty(name, _size);
_small_store = new SmallBlockStore(new BlockWritable[ 0 ]);
_property.setDocument(this);
}
Constructor from large blocks Parameters:
name - the name of the POIFSDocument
blocks - the big blocks making up the POIFSDocument
length - the actual length of the POIFSDocument
Throws:
IOException -
- exception:
IOException -
|
public POIFSDocument(String name,
SmallDocumentBlock[] blocks,
int length) {
_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);
}
Constructor from small blocks Parameters:
name - the name of the POIFSDocument
blocks - the small blocks making up the POIFSDocument
length - the actual length of the POIFSDocument
|
public POIFSDocument(String name,
ListManagedBlock[] blocks,
int length) throws IOException {
_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 ]);
}
}
Constructor from small blocks Parameters:
name - the name of the POIFSDocument
blocks - the small blocks making up the POIFSDocument
length - the actual length of the POIFSDocument
Throws:
IOException -
- exception:
IOException -
|
public POIFSDocument(String name,
int size,
POIFSDocumentPath path,
POIFSWriterListener writer) throws IOException {
_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);
}
}
Parameters:
name - the name of the POIFSDocument
size - the length of the POIFSDocument
path - the path of the POIFSDocument
writer - the writer who will eventually write the document
contents
Throws:
IOException - thrown on read errors
- exception:
IOException - thrown on read errors
|
| Method from org.apache.poi.poifs.filesystem.POIFSDocument Detail: |
public int countBlocks() {
return _big_store.countBlocks();
}
Return the number of BigBlock's this instance uses |
DocumentProperty getDocumentProperty() {
return _property;
}
|
public String getShortDescription() {
StringBuffer buffer = new StringBuffer();
buffer.append("Document: \"").append(_property.getName())
.append("\"");
buffer.append(" size = ").append(getSize());
return buffer.toString();
}
Provides a short description of the object, to be used when a
POIFSViewable object has not provided its contents. |
public int getSize() {
return _size;
}
|
public BlockWritable[] getSmallBlocks() {
return _small_store.getBlocks();
}
return the array of SmallDocumentBlocks used |
public Object[] getViewableArray() {
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;
}
Get an array of objects, some of which may implement
POIFSViewable |
public Iterator getViewableIterator() {
return Collections.EMPTY_LIST.iterator();
}
Get an Iterator of objects, some of which may implement
POIFSViewable |
public boolean preferArray() {
return true;
}
Give viewers a hint as to whether to call getViewableArray or
getViewableIterator |
void read(byte[] buffer,
int offset) {
if (_property.shouldUseSmallBlocks())
{
SmallDocumentBlock.read(_small_store.getBlocks(), buffer, offset);
}
else
{
DocumentBlock.read(_big_store.getBlocks(), buffer, offset);
}
}
read data from the internal stores |
public void setStartBlock(int index) {
_property.setStartBlock(index);
}
Set the start block for this instance |
public void writeBlocks(OutputStream stream) throws IOException {
_big_store.writeBlocks(stream);
}
Write the storage to an OutputStream |