Package org.apache.poi.poifs.filesystem

Examples of org.apache.poi.poifs.filesystem.DirectoryEntry


    new POIFSFileSystem(new ByteArrayInputStream(out.toByteArray()));
  }

  public void testEmptyDocumentWithFriend() throws IOException {
    POIFSFileSystem fs = new POIFSFileSystem();
    DirectoryEntry dir = fs.getRoot();
    dir.createDocument("Bar", new ByteArrayInputStream(new byte[] { 0 }));
    dir.createDocument("Foo", new ByteArrayInputStream(new byte[] { }));
   
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    fs.writeFilesystem(out);
    new POIFSFileSystem(new ByteArrayInputStream(out.toByteArray()));
  }
View Full Code Here


    new POIFSFileSystem(new ByteArrayInputStream(out.toByteArray()));
  }

  public void testEmptyDocumentEventWithFriend() throws IOException {
    POIFSFileSystem fs = new POIFSFileSystem();
    DirectoryEntry dir = fs.getRoot();
    dir.createDocument("Bar", 1, new POIFSWriterListener() {
      public void processPOIFSWriterEvent(POIFSWriterEvent event) {
        try {
          event.getStream().write(0);
        } catch (IOException exception) {
          throw new RuntimeException("exception on write: " + exception);
        }
      }
    });
    dir.createDocument("Foo", 0, new POIFSWriterListener() {
      public void processPOIFSWriterEvent(POIFSWriterEvent event) {
      }
    });
   
    ByteArrayOutputStream out = new ByteArrayOutputStream();
View Full Code Here

            final File doc = docs[i];
            System.out.println("Reading file " + doc);

            /* Read a test document <em>doc</em> into a POI filesystem. */
            final POIFSFileSystem poifs = new POIFSFileSystem(new FileInputStream(doc));
            final DirectoryEntry dir = poifs.getRoot();
            DocumentEntry dsiEntry = null;
            try
            {
                dsiEntry = (DocumentEntry) dir.getEntry(DocumentSummaryInformation.DEFAULT_STREAM_NAME);
            }
            catch (FileNotFoundException ex)
            {
                /*
                 * A missing document summary information stream is not an error
View Full Code Here

    System.out.println();
  }

  public void testSingleEmptyDocument() throws IOException {
    POIFSFileSystem fs = new POIFSFileSystem();
    DirectoryEntry dir = fs.getRoot();
    dir.createDocument("Foo", new ByteArrayInputStream(new byte[] { }));
   
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    fs.writeFilesystem(out);
    new POIFSFileSystem(new ByteArrayInputStream(out.toByteArray()));
  }
View Full Code Here

      e.printStackTrace();
      fail();
    }
      assertNotNull(poifs);
       /* Read the document summary information. */
       DirectoryEntry dir = poifs.getRoot();
      
       try
       {
           DocumentEntry dsiEntry = (DocumentEntry)
               dir.getEntry(DocumentSummaryInformation.DEFAULT_STREAM_NAME);
           DocumentInputStream dis = new DocumentInputStream(dsiEntry);
           PropertySet ps = new PropertySet(dis);
           dis.close();
           dsi = new DocumentSummaryInformation(ps);
       }
       catch (FileNotFoundException ex)
       {
           fail();
       } catch (IOException e) {
      e.printStackTrace();
      fail();
    } catch (NoPropertySetStreamException e) {
      e.printStackTrace();
      fail();
    } catch (MarkUnsupportedException e) {
      e.printStackTrace();
      fail();
    } catch (UnexpectedPropertySetTypeException e) {
      e.printStackTrace();
      fail();
    }
      try
        {
            DocumentEntry dsiEntry = (DocumentEntry)
                dir.getEntry(SummaryInformation.DEFAULT_STREAM_NAME);
            DocumentInputStream dis = new DocumentInputStream(dsiEntry);
            PropertySet ps = new PropertySet(dis);
            dis.close();
            si = new SummaryInformation(ps);
         
View Full Code Here

   * @throws IOException
   *
   */
  public void reparseFileSystem() throws IOException {
    // first clear this object of all chunks
    DirectoryEntry root = this.fs.getRoot();
    Iterator iter = root.getEntries();
   
    this.directoryMap = this.processPOIIterator(iter);
  }
View Full Code Here

                           final PropertySet si)
        throws WritingNotSupportedException, IOException
           
        {
            /* Get the directory entry for the target stream. */
            final DirectoryEntry de = getPath(poiFs, path);

            /* Create a mutable property set as a copy of the original read-only
             * property set. */
            final MutablePropertySet mps = new MutablePropertySet(si);
           
            /* Retrieve the section containing the properties to modify. A
             * summary information property set contains exactly one section. */
            final MutableSection s =
                (MutableSection) mps.getSections().get(0);

            /* Set the properties. */
            s.setProperty(PropertyIDMap.PID_AUTHOR, Variant.VT_LPSTR,
                          "Rainer Klute");
            s.setProperty(PropertyIDMap.PID_TITLE, Variant.VT_LPWSTR,
                          "Test");

            /* Create an input stream containing the bytes the property set
             * stream consists of. */
            final InputStream pss = mps.toInputStream();

            /* Write the property set stream to the POIFS. */
            de.createDocument(name, pss);
        }
View Full Code Here

                         final POIFSDocumentPath path,
                         final String name,
                         final PropertySet ps)
            throws WritingNotSupportedException, IOException
        {
            final DirectoryEntry de = getPath(poiFs, path);
            final MutablePropertySet mps = new MutablePropertySet(ps);
            de.createDocument(name, mps.toInputStream());
        }
View Full Code Here

        public void copy(final POIFSFileSystem poiFs,
                         final POIFSDocumentPath path,
                         final String name,
                         final DocumentInputStream stream) throws IOException
        {
            final DirectoryEntry de = getPath(poiFs, path);
            final ByteArrayOutputStream out = new ByteArrayOutputStream();
            int c;
            while ((c = stream.read()) != -1)
                out.write(c);
            stream.close();
            out.close();
            final InputStream in =
                new ByteArrayInputStream(out.toByteArray());
            de.createDocument(name, in);
        }
View Full Code Here

        {
            try
            {
                /* Check whether this directory has already been created. */
                final String s = path.toString();
                DirectoryEntry de = (DirectoryEntry) paths.get(s);
                if (de != null)
                    /* Yes: return the corresponding DirectoryEntry. */
                    return de;

                /* No: We have to create the directory - or return the root's
                 * DirectoryEntry. */
                int l = path.length();
                if (l == 0)
                    /* Get the root directory. It does not have to be created
                     * since it always exists in a POIFS. */
                    de = poiFs.getRoot();
                else
                {
                    /* Create a subordinate directory. The first step is to
                     * ensure that the parent directory exists: */
                    de = getPath(poiFs, path.getParent());
                    /* Now create the target directory: */
                    de = de.createDirectory(path.getComponent
                                            (path.length() - 1));
                }
                paths.put(s, de);
                return de;
            }
View Full Code Here

TOP

Related Classes of org.apache.poi.poifs.filesystem.DirectoryEntry

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.