]> source.dussan.org Git - poi.git/commitdiff
Fix up constructor to ensure that the filesystem objects are around when we need...
authorNick Burch <nick@apache.org>
Fri, 25 Mar 2011 16:53:26 +0000 (16:53 +0000)
committerNick Burch <nick@apache.org>
Fri, 25 Mar 2011 16:53:26 +0000 (16:53 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1085467 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/poi/poifs/filesystem/DirectoryNode.java
src/testcases/org/apache/poi/poifs/filesystem/TestDocumentInputStream.java

index ea733ea879490e52134883b075a17afaf9bb733f..738a8e1a90a59693fb51e538ff3866d60a7360aa 100644 (file)
@@ -70,8 +70,7 @@ public class DirectoryNode
                   final POIFSFileSystem filesystem,
                   final DirectoryNode parent)
     {
-       this(property, parent);
-       _ofilesystem = filesystem;
+       this(property, parent, filesystem, (NPOIFSFileSystem)null);
     }
     
     /**
@@ -86,14 +85,18 @@ public class DirectoryNode
                   final NPOIFSFileSystem nfilesystem,
                   final DirectoryNode parent)
     {
-       this(property, parent);
-       _nfilesystem = nfilesystem;
+       this(property, parent, (POIFSFileSystem)null, nfilesystem);
     }
     
     private DirectoryNode(final DirectoryProperty property,
-                          final DirectoryNode parent)
+                          final DirectoryNode parent,
+                          final POIFSFileSystem ofilesystem,
+                          final NPOIFSFileSystem nfilesystem)
     {
         super(property, parent);
+        this._ofilesystem = ofilesystem;
+        this._nfilesystem = nfilesystem;
+        
         if (parent == null)
         {
             _path = new POIFSDocumentPath();
index 0b1b6b096a6a6a2baf2097a2dbad451b4524ac2e..e0600e8d56f338d9571439e6c4b92073d6b89d4d 100644 (file)
 package org.apache.poi.poifs.filesystem;
 
 import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.FileInputStream;
 import java.io.IOException;
 import java.util.Arrays;
 
 import junit.framework.TestCase;
 
+import org.apache.poi.POIDataSamples;
 import org.apache.poi.poifs.property.DirectoryProperty;
 import org.apache.poi.poifs.storage.RawDataBlock;
 
@@ -365,4 +368,47 @@ public final class TestDocumentInputStream extends TestCase {
                      stream.skip(2 + ( long ) Integer.MAX_VALUE));
         assertEquals(0, stream.available());
     }
+    
+    /**
+     * Test that we can read files at multiple levels down the tree
+     */
+    public void testReadMultipleTreeLevels() throws Exception {
+       final POIDataSamples _samples = POIDataSamples.getPublisherInstance();
+       File sample = _samples.getFile("Sample.pub");
+       
+       DocumentInputStream stream;
+       
+       NPOIFSFileSystem npoifs = new NPOIFSFileSystem(sample);
+       POIFSFileSystem  opoifs = new POIFSFileSystem(new FileInputStream(sample));
+       
+       // Ensure we have what we expect on the root
+       assertEquals(npoifs, npoifs.getRoot().getNFileSystem());
+       assertEquals(null,   npoifs.getRoot().getFileSystem());
+       assertEquals(opoifs, opoifs.getRoot().getFileSystem());
+       assertEquals(null,   opoifs.getRoot().getNFileSystem());
+       
+       // Check inside
+       for(DirectoryNode root : new DirectoryNode[] { opoifs.getRoot(), npoifs.getRoot() }) {
+          // Top Level
+          Entry top = root.getEntry("Contents");
+          assertEquals(true, top.isDocumentEntry());
+          stream = root.createDocumentInputStream(top);
+          stream.read();
+          
+          // One Level Down
+          DirectoryNode escher = (DirectoryNode)root.getEntry("Escher");
+          Entry one = escher.getEntry("EscherStm");
+          assertEquals(true, one.isDocumentEntry());
+          stream = escher.createDocumentInputStream(one);
+          stream.read();
+          
+          // Two Levels Down
+          DirectoryNode quill = (DirectoryNode)root.getEntry("Quill");
+          DirectoryNode quillSub = (DirectoryNode)quill.getEntry("QuillSub");
+          Entry two = quillSub.getEntry("CONTENTS");
+          assertEquals(true, two.isDocumentEntry());
+          stream = quillSub.createDocumentInputStream(two);
+          stream.read();
+       }
+    }
 }