use of org.apache.poi.poifs.property.Property 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.property.Property in project poi by apache.
the class OPOIFSFileSystem method processProperties.
private void processProperties(final BlockList small_blocks, final BlockList big_blocks, final Iterator<Property> properties, final DirectoryNode dir, final int headerPropertiesStartAt) throws IOException {
while (properties.hasNext()) {
Property property = properties.next();
String name = property.getName();
DirectoryNode parent = (dir == null) ? ((DirectoryNode) getRoot()) : dir;
if (property.isDirectory()) {
DirectoryNode new_dir = (DirectoryNode) parent.createDirectory(name);
new_dir.setStorageClsid(property.getStorageClsid());
processProperties(small_blocks, big_blocks, ((DirectoryProperty) property).getChildren(), new_dir, headerPropertiesStartAt);
} else {
int startBlock = property.getStartBlock();
int size = property.getSize();
OPOIFSDocument document = null;
if (property.shouldUseSmallBlocks()) {
document = new OPOIFSDocument(name, small_blocks.fetchBlocks(startBlock, headerPropertiesStartAt), size);
} else {
document = new OPOIFSDocument(name, big_blocks.fetchBlocks(startBlock, headerPropertiesStartAt), size);
}
parent.createDocument(document);
}
}
}
use of org.apache.poi.poifs.property.Property in project poi by apache.
the class POIFSHeaderDumper method displayProperties.
public static void displayProperties(DirectoryProperty prop, String indent) {
String nextIndent = indent + " ";
System.out.println(indent + "-> " + prop.getName());
for (Property cp : prop) {
if (cp instanceof DirectoryProperty) {
displayProperties((DirectoryProperty) cp, nextIndent);
} else {
System.out.println(nextIndent + "=> " + cp.getName());
System.out.print(nextIndent + " " + cp.getSize() + " bytes in ");
if (cp.shouldUseSmallBlocks()) {
System.out.print("mini");
} else {
System.out.print("main");
}
System.out.println(" stream, starts at " + cp.getStartBlock());
}
}
}
use of org.apache.poi.poifs.property.Property in project poi by apache.
the class TestNPOIFSFileSystem method writeZeroLengthEntries.
@Test
public void writeZeroLengthEntries() throws IOException {
NPOIFSFileSystem fs1 = new NPOIFSFileSystem();
DirectoryNode testDir = fs1.getRoot();
DocumentEntry miniDoc;
DocumentEntry normDoc;
DocumentEntry emptyDoc;
// Add mini and normal sized entries to start
byte[] mini2 = new byte[] { -42, 0, -1, -2, -3, -4, -42 };
testDir.createDocument("Mini2", new ByteArrayInputStream(mini2));
// Add to the main stream
byte[] main4106 = new byte[4106];
main4106[0] = 41;
main4106[4105] = 42;
testDir.createDocument("Normal4106", new ByteArrayInputStream(main4106));
// Now add some empty ones
byte[] empty = new byte[0];
testDir.createDocument("empty-1", new ByteArrayInputStream(empty));
testDir.createDocument("empty-2", new ByteArrayInputStream(empty));
testDir.createDocument("empty-3", new ByteArrayInputStream(empty));
// Check
miniDoc = (DocumentEntry) testDir.getEntry("Mini2");
assertContentsMatches(mini2, miniDoc);
normDoc = (DocumentEntry) testDir.getEntry("Normal4106");
assertContentsMatches(main4106, normDoc);
emptyDoc = (DocumentEntry) testDir.getEntry("empty-1");
assertContentsMatches(empty, emptyDoc);
emptyDoc = (DocumentEntry) testDir.getEntry("empty-2");
assertContentsMatches(empty, emptyDoc);
emptyDoc = (DocumentEntry) testDir.getEntry("empty-3");
assertContentsMatches(empty, emptyDoc);
// Look at the properties entry, and check the empty ones
// have zero size and no start block
NPropertyTable props = fs1._get_property_table();
Iterator<Property> propsIt = props.getRoot().getChildren();
Property prop = propsIt.next();
assertEquals("Mini2", prop.getName());
assertEquals(0, prop.getStartBlock());
assertEquals(7, prop.getSize());
prop = propsIt.next();
assertEquals("Normal4106", prop.getName());
// BAT, Props, SBAT, MIni
assertEquals(4, prop.getStartBlock());
assertEquals(4106, prop.getSize());
prop = propsIt.next();
assertEquals("empty-1", prop.getName());
assertEquals(POIFSConstants.END_OF_CHAIN, prop.getStartBlock());
assertEquals(0, prop.getSize());
prop = propsIt.next();
assertEquals("empty-2", prop.getName());
assertEquals(POIFSConstants.END_OF_CHAIN, prop.getStartBlock());
assertEquals(0, prop.getSize());
prop = propsIt.next();
assertEquals("empty-3", prop.getName());
assertEquals(POIFSConstants.END_OF_CHAIN, prop.getStartBlock());
assertEquals(0, prop.getSize());
// Save and re-check
NPOIFSFileSystem fs2 = writeOutAndReadBack(fs1);
fs1.close();
testDir = fs2.getRoot();
miniDoc = (DocumentEntry) testDir.getEntry("Mini2");
assertContentsMatches(mini2, miniDoc);
normDoc = (DocumentEntry) testDir.getEntry("Normal4106");
assertContentsMatches(main4106, normDoc);
emptyDoc = (DocumentEntry) testDir.getEntry("empty-1");
assertContentsMatches(empty, emptyDoc);
emptyDoc = (DocumentEntry) testDir.getEntry("empty-2");
assertContentsMatches(empty, emptyDoc);
emptyDoc = (DocumentEntry) testDir.getEntry("empty-3");
assertContentsMatches(empty, emptyDoc);
// Check that a mini-stream was assigned, with one block used
assertEquals(3, testDir.getProperty().getStartBlock());
assertEquals(64, testDir.getProperty().getSize());
// All done
fs2.close();
}
use of org.apache.poi.poifs.property.Property in project poi by apache.
the class PropertyBlock method createPropertyBlockArray.
/**
* Create an array of PropertyBlocks from an array of Property
* instances, creating empty Property instances to make up any
* shortfall
*
* @param properties the Property instances to be converted into
* PropertyBlocks, in a java List
*
* @return the array of newly created PropertyBlock instances
*/
public static BlockWritable[] createPropertyBlockArray(final POIFSBigBlockSize bigBlockSize, final List<Property> properties) {
int _properties_per_block = bigBlockSize.getPropertiesPerBlock();
int block_count = (properties.size() + _properties_per_block - 1) / _properties_per_block;
Property[] to_be_written = new Property[block_count * _properties_per_block];
System.arraycopy(properties.toArray(new Property[0]), 0, to_be_written, 0, properties.size());
for (int j = properties.size(); j < to_be_written.length; j++) {
// create an instance of an anonymous inner class that
// extends Property
to_be_written[j] = new Property() {
protected void preWrite() {
}
public boolean isDirectory() {
return false;
}
};
}
BlockWritable[] rvalue = new BlockWritable[block_count];
for (int j = 0; j < block_count; j++) {
rvalue[j] = new PropertyBlock(bigBlockSize, to_be_written, j * _properties_per_block);
}
return rvalue;
}
Aggregations