use of org.apache.poi.poifs.filesystem.OPOIFSDocument in project poi by apache.
the class POIFSReader method processProperties.
private void processProperties(final BlockList small_blocks, final BlockList big_blocks, final Iterator<Property> properties, final POIFSDocumentPath path) throws IOException {
if (!properties.hasNext() && notifyEmptyDirectories) {
Iterator<POIFSReaderListener> listeners = registry.getListeners(path, ".");
while (listeners.hasNext()) {
POIFSReaderListener pl = listeners.next();
POIFSReaderEvent pe = new POIFSReaderEvent(null, path, null);
pl.processPOIFSReaderEvent(pe);
}
return;
}
while (properties.hasNext()) {
Property property = properties.next();
String name = property.getName();
if (property.isDirectory()) {
POIFSDocumentPath new_path = new POIFSDocumentPath(path, new String[] { name });
DirectoryProperty dp = (DirectoryProperty) property;
processProperties(small_blocks, big_blocks, dp.getChildren(), new_path);
} else {
int startBlock = property.getStartBlock();
Iterator<POIFSReaderListener> listeners = registry.getListeners(path, name);
if (listeners.hasNext()) {
int size = property.getSize();
OPOIFSDocument document = null;
if (property.shouldUseSmallBlocks()) {
document = new OPOIFSDocument(name, small_blocks.fetchBlocks(startBlock, -1), size);
} else {
document = new OPOIFSDocument(name, big_blocks.fetchBlocks(startBlock, -1), size);
}
while (listeners.hasNext()) {
POIFSReaderListener listener = listeners.next();
listener.processPOIFSReaderEvent(new POIFSReaderEvent(new DocumentInputStream(document), path, name));
}
} else {
// consume the document's data and discard it
if (property.shouldUseSmallBlocks()) {
small_blocks.fetchBlocks(startBlock, -1);
} else {
big_blocks.fetchBlocks(startBlock, -1);
}
}
}
}
}
use of org.apache.poi.poifs.filesystem.OPOIFSDocument in project poi by apache.
the class TestSmallBlockTableWriter method testWritingConstructor.
public void testWritingConstructor() throws IOException {
List<OPOIFSDocument> documents = new ArrayList<OPOIFSDocument>();
documents.add(new OPOIFSDocument("doc340", new ByteArrayInputStream(new byte[340])));
documents.add(new OPOIFSDocument("doc5000", new ByteArrayInputStream(new byte[5000])));
documents.add(new OPOIFSDocument("doc0", new ByteArrayInputStream(new byte[0])));
documents.add(new OPOIFSDocument("doc1", new ByteArrayInputStream(new byte[1])));
documents.add(new OPOIFSDocument("doc2", new ByteArrayInputStream(new byte[2])));
documents.add(new OPOIFSDocument("doc3", new ByteArrayInputStream(new byte[3])));
documents.add(new OPOIFSDocument("doc4", new ByteArrayInputStream(new byte[4])));
documents.add(new OPOIFSDocument("doc5", new ByteArrayInputStream(new byte[5])));
documents.add(new OPOIFSDocument("doc6", new ByteArrayInputStream(new byte[6])));
documents.add(new OPOIFSDocument("doc7", new ByteArrayInputStream(new byte[7])));
documents.add(new OPOIFSDocument("doc8", new ByteArrayInputStream(new byte[8])));
documents.add(new OPOIFSDocument("doc9", new ByteArrayInputStream(new byte[9])));
HeaderBlock header = new HeaderBlock(POIFSConstants.SMALLER_BIG_BLOCK_SIZE_DETAILS);
RootProperty root = new PropertyTable(header).getRoot();
SmallBlockTableWriter sbtw = new SmallBlockTableWriter(POIFSConstants.SMALLER_BIG_BLOCK_SIZE_DETAILS, documents, root);
BlockAllocationTableWriter bat = sbtw.getSBAT();
// 15 small blocks: 6 for doc340, 0 for doc5000 (too big), 0
// for doc0 (no storage needed), 1 each for doc1 through doc9
assertEquals(15 * 64, root.getSize());
// 15 small blocks rounds up to 2 big blocks
assertEquals(2, sbtw.countBlocks());
int start_block = 1000 + root.getStartBlock();
sbtw.setStartBlock(start_block);
assertEquals(start_block, root.getStartBlock());
}
Aggregations