Search in sources :

Example 1 with DocumentProperty

use of org.apache.poi.poifs.property.DocumentProperty in project poi by apache.

the class DirectoryNode method createDocument.

/**
     * create a new DocumentEntry
     *
     * @param document the new document
     *
     * @return the new DocumentEntry
     *
     * @exception IOException
     */
DocumentEntry createDocument(final NPOIFSDocument document) throws IOException {
    DocumentProperty property = document.getDocumentProperty();
    DocumentNode rval = new DocumentNode(property, this);
    ((DirectoryProperty) getProperty()).addChild(property);
    _nfilesystem.addDocument(document);
    _entries.add(rval);
    _byname.put(property.getName(), rval);
    return rval;
}
Also used : DocumentProperty(org.apache.poi.poifs.property.DocumentProperty) DirectoryProperty(org.apache.poi.poifs.property.DirectoryProperty)

Example 2 with DocumentProperty

use of org.apache.poi.poifs.property.DocumentProperty in project poi by apache.

the class DirectoryNode method createDocument.

/**
     * create a new DocumentEntry
     *
     * @param document the new document
     *
     * @return the new DocumentEntry
     *
     * @exception IOException
     */
DocumentEntry createDocument(final OPOIFSDocument document) throws IOException {
    DocumentProperty property = document.getDocumentProperty();
    DocumentNode rval = new DocumentNode(property, this);
    ((DirectoryProperty) getProperty()).addChild(property);
    _ofilesystem.addDocument(document);
    _entries.add(rval);
    _byname.put(property.getName(), rval);
    return rval;
}
Also used : DocumentProperty(org.apache.poi.poifs.property.DocumentProperty) DirectoryProperty(org.apache.poi.poifs.property.DirectoryProperty)

Example 3 with DocumentProperty

use of org.apache.poi.poifs.property.DocumentProperty in project poi by apache.

the class TestDocument method testOPOIFSDocument.

/**
     * Integration test -- really about all we can do
     */
public void testOPOIFSDocument() throws IOException {
    // verify correct number of blocks get created for document
    // that is exact multituple of block size
    OPOIFSDocument document;
    byte[] array = new byte[4096];
    for (int j = 0; j < array.length; j++) {
        array[j] = (byte) j;
    }
    document = new OPOIFSDocument("foo", new SlowInputStream(new ByteArrayInputStream(array)));
    checkDocument(document, array);
    // verify correct number of blocks get created for document
    // that is not an exact multiple of block size
    array = new byte[4097];
    for (int j = 0; j < array.length; j++) {
        array[j] = (byte) j;
    }
    document = new OPOIFSDocument("bar", new ByteArrayInputStream(array));
    checkDocument(document, array);
    // verify correct number of blocks get created for document
    // that is small
    array = new byte[4095];
    for (int j = 0; j < array.length; j++) {
        array[j] = (byte) j;
    }
    document = new OPOIFSDocument("_bar", new ByteArrayInputStream(array));
    checkDocument(document, array);
    // verify correct number of blocks get created for document
    // that is rather small
    array = new byte[199];
    for (int j = 0; j < array.length; j++) {
        array[j] = (byte) j;
    }
    document = new OPOIFSDocument("_bar2", new ByteArrayInputStream(array));
    checkDocument(document, array);
    // verify that output is correct
    array = new byte[4097];
    for (int j = 0; j < array.length; j++) {
        array[j] = (byte) j;
    }
    document = new OPOIFSDocument("foobar", new ByteArrayInputStream(array));
    checkDocument(document, array);
    // what a big file!!
    document.setStartBlock(0x12345678);
    DocumentProperty property = document.getDocumentProperty();
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    property.writeData(stream);
    byte[] output = stream.toByteArray();
    byte[] array2 = { (byte) 'f', (byte) 0, (byte) 'o', (byte) 0, (byte) 'o', (byte) 0, (byte) 'b', (byte) 0, (byte) 'a', (byte) 0, (byte) 'r', (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 14, (byte) 0, (byte) 2, (byte) 1, (byte) -1, (byte) -1, (byte) -1, (byte) -1, (byte) -1, (byte) -1, (byte) -1, (byte) -1, (byte) -1, (byte) -1, (byte) -1, (byte) -1, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0x78, (byte) 0x56, (byte) 0x34, (byte) 0x12, (byte) 1, (byte) 16, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0 };
    assertEquals(array2.length, output.length);
    for (int j = 0; j < output.length; j++) {
        assertEquals("Checking property offset " + j, array2[j], output[j]);
    }
}
Also used : DocumentProperty(org.apache.poi.poifs.property.DocumentProperty) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 4 with DocumentProperty

use of org.apache.poi.poifs.property.DocumentProperty in project poi by apache.

the class TestDocumentNode method testConstructor.

/**
     * test constructor
     */
public void testConstructor() throws IOException {
    DirectoryProperty property1 = new DirectoryProperty("directory");
    RawDataBlock[] rawBlocks = new RawDataBlock[4];
    ByteArrayInputStream stream = new ByteArrayInputStream(new byte[2048]);
    for (int j = 0; j < 4; j++) {
        rawBlocks[j] = new RawDataBlock(stream);
    }
    OPOIFSDocument document = new OPOIFSDocument("document", rawBlocks, 2000);
    DocumentProperty property2 = document.getDocumentProperty();
    DirectoryNode parent = new DirectoryNode(property1, (POIFSFileSystem) null, null);
    DocumentNode node = new DocumentNode(property2, parent);
    // verify we can retrieve the document
    assertEquals(property2.getDocument(), node.getDocument());
    // verify we can get the size
    assertEquals(property2.getSize(), node.getSize());
    // verify isDocumentEntry returns true
    assertTrue(node.isDocumentEntry());
    // verify isDirectoryEntry returns false
    assertTrue(!node.isDirectoryEntry());
    // verify getName behaves correctly
    assertEquals(property2.getName(), node.getName());
    // verify getParent behaves correctly
    assertEquals(parent, node.getParent());
}
Also used : DocumentProperty(org.apache.poi.poifs.property.DocumentProperty) DirectoryProperty(org.apache.poi.poifs.property.DirectoryProperty) RawDataBlock(org.apache.poi.poifs.storage.RawDataBlock)

Example 5 with DocumentProperty

use of org.apache.poi.poifs.property.DocumentProperty in project poi by apache.

the class TestDirectoryNode method testNonEmptyConstructor.

/**
     * test non-trivial constructor (a DirectoryNode with children)
     */
public void testNonEmptyConstructor() throws IOException {
    DirectoryProperty property1 = new DirectoryProperty("parent");
    DirectoryProperty property2 = new DirectoryProperty("child1");
    property1.addChild(property2);
    property1.addChild(new DocumentProperty("child2", 2000));
    property2.addChild(new DocumentProperty("child3", 30000));
    DirectoryNode node = new DirectoryNode(property1, new POIFSFileSystem(), null);
    // verify that getEntries behaves correctly
    int count = 0;
    Iterator<Entry> iter = node.getEntries();
    while (iter.hasNext()) {
        count++;
        iter.next();
    }
    assertEquals(2, count);
    // verify behavior of isEmpty
    assertTrue(!node.isEmpty());
    // verify behavior of getEntryCount
    assertEquals(2, node.getEntryCount());
    // verify behavior of getEntry
    DirectoryNode child1 = (DirectoryNode) node.getEntry("child1");
    child1.getEntry("child3");
    node.getEntry("child2");
    try {
        node.getEntry("child3");
        fail("should have caught FileNotFoundException");
    } catch (FileNotFoundException ignored) {
    // as expected
    }
    // verify behavior of isDirectoryEntry
    assertTrue(node.isDirectoryEntry());
    // verify behavior of getName
    assertEquals(property1.getName(), node.getName());
    // verify behavior of isDocumentEntry
    assertTrue(!node.isDocumentEntry());
    // verify behavior of getParent
    assertNull(node.getParent());
}
Also used : DocumentProperty(org.apache.poi.poifs.property.DocumentProperty) DirectoryProperty(org.apache.poi.poifs.property.DirectoryProperty) FileNotFoundException(java.io.FileNotFoundException)

Aggregations

DocumentProperty (org.apache.poi.poifs.property.DocumentProperty)5 DirectoryProperty (org.apache.poi.poifs.property.DirectoryProperty)4 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 RawDataBlock (org.apache.poi.poifs.storage.RawDataBlock)1