Package org.apache.poi.poifs.property

Examples of org.apache.poi.poifs.property.DocumentProperty


   * @param blocks the small blocks making up the POIFSDocument
   * @param 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(EMPTY_BIG_BLOCK_ARRAY);
      _small_store = new SmallBlockStore(convertRawBlocksToSmallBlocks(blocks));
    } else {
View Full Code Here


      }
    }
    DocumentBlock[] bigBlocks = blocks.toArray(new DocumentBlock[blocks.size()]);

    _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 {
View Full Code Here

   * @param path the path of the POIFSDocument
   * @param writer the writer who will eventually write the document contents
   */
  public POIFSDocument(String name, int size, POIFSDocumentPath path, POIFSWriterListener writer) {
    _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(EMPTY_BIG_BLOCK_ARRAY);
    } else {
View Full Code Here

    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;
View Full Code Here

        {
            rawBlocks[ j ] = new RawDataBlock(stream);
        }
        POIFSDocument    document  = new POIFSDocument("document", rawBlocks,
                                         2000);
        DocumentProperty property2 = document.getDocumentProperty();
        DirectoryNode    parent    = new DirectoryNode(property1, 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());
    }
View Full Code Here

     */

    DocumentEntry createDocument(final POIFSDocument document)
        throws IOException
    {
        DocumentProperty property = document.getDocumentProperty();
        DocumentNode     rval     = new DocumentNode(property, this);

        (( DirectoryProperty ) getProperty()).addChild(property);
        _filesystem.addDocument(document);
        _entries.add(rval);
        _byname.put(property.getName(), rval);
        return rval;
    }
View Full Code Here

    {
        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;
View Full Code Here

        }
        document = new POIFSDocument("foobar",
                                     new ByteArrayInputStream(array));
        checkDocument(document, array);
        document.setStartBlock(0x12345678);   // what a big file!!
        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,
View Full Code Here

    private void verifyReadingProperty(int index, byte [] input, int offset,
                                       String name)
        throws IOException
    {
        DocumentProperty      property = new DocumentProperty(index, input,
                                             offset);
        ByteArrayOutputStream stream   = new ByteArrayOutputStream(128);
        byte[]                expected = new byte[ 128 ];

        System.arraycopy(input, offset, expected, 0, 128);
        property.writeData(stream);
        byte[] output = stream.toByteArray();

        assertEquals(128, output.length);
        for (int j = 0; j < 128; j++)
        {
            assertEquals("mismatch at offset " + j, expected[ j ],
                         output[ j ]);
        }
        assertEquals(index, property.getIndex());
        assertEquals(name, property.getName());
    }
View Full Code Here

    }

    private void verifyProperty(String name, int size)
        throws IOException
    {
        DocumentProperty property = new DocumentProperty(name, size);

        if (size >= 4096)
        {
            assertTrue(!property.shouldUseSmallBlocks());
        }
        else
        {
            assertTrue(property.shouldUseSmallBlocks());
        }
        byte[] testblock = new byte[ 128 ];
        int    index     = 0;

        for (; index < 0x40; index++)
        {
            testblock[ index ] = ( byte ) 0;
        }
        int limit = Math.min(31, name.length());

        testblock[ index++ ] = ( byte ) (2 * (limit + 1));
        testblock[ index++ ] = ( byte ) 0;
        testblock[ index++ ] = ( byte ) 2;
        testblock[ index++ ] = ( byte ) 1;
        for (; index < 0x50; index++)
        {
            testblock[ index ] = ( byte ) 0xFF;
        }
        for (; index < 0x78; index++)
        {
            testblock[ index ] = ( byte ) 0;
        }
        int sz = size;

        testblock[ index++ ] = ( byte ) sz;
        sz                   /= 256;
        testblock[ index++ ] = ( byte ) sz;
        sz                   /= 256;
        testblock[ index++ ] = ( byte ) sz;
        sz                   /= 256;
        testblock[ index++ ] = ( byte ) sz;
        for (; index < 0x80; index++)
        {
            testblock[ index ] = ( byte ) 0x0;
        }
        byte[] name_bytes = name.getBytes();

        for (index = 0; index < limit; index++)
        {
            testblock[ index * 2 ] = name_bytes[ index ];
        }
        ByteArrayOutputStream stream = new ByteArrayOutputStream(512);

        property.writeData(stream);
        byte[] output = stream.toByteArray();

        assertEquals(testblock.length, output.length);
        for (int j = 0; j < testblock.length; j++)
        {
View Full Code Here

TOP

Related Classes of org.apache.poi.poifs.property.DocumentProperty

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.