From: Nick Burch Date: Tue, 26 May 2015 18:04:00 +0000 (+0000) Subject: #56791 Make NPOIFS the default when POIFSFileSystem is requested X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=b2d1c1b6ac2c393cc6c8ba10f95a73ad8c240012;p=poi.git #56791 Make NPOIFS the default when POIFSFileSystem is requested git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1681804 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/java/org/apache/poi/poifs/filesystem/DirectoryNode.java b/src/java/org/apache/poi/poifs/filesystem/DirectoryNode.java index e8c6638bf6..9be71a5ccf 100644 --- a/src/java/org/apache/poi/poifs/filesystem/DirectoryNode.java +++ b/src/java/org/apache/poi/poifs/filesystem/DirectoryNode.java @@ -145,14 +145,15 @@ public class DirectoryNode /** * @return the filesystem that this belongs to - * TODO Temporary workaround during #56791 */ - public POIFSFileSystem getFileSystem() + public NPOIFSFileSystem getFileSystem() { - return (POIFSFileSystem)_ofilesystem; + return _nfilesystem; } /** + * If this is OPOIFS based, return the NPOIFSFileSystem + * that this belong to, otherwise Null if NPOIFS based * @return the filesystem that this belongs to */ public OPOIFSFileSystem getOFileSystem() @@ -161,6 +162,8 @@ public class DirectoryNode } /** + * If this is NPOIFS based, return the NPOIFSFileSystem + * that this belong to, otherwise Null if OPOIFS based * @return the filesystem that this belongs to */ public NPOIFSFileSystem getNFileSystem() diff --git a/src/java/org/apache/poi/poifs/filesystem/POIFSFileSystem.java b/src/java/org/apache/poi/poifs/filesystem/POIFSFileSystem.java index b8afa2f707..5afb4eb8fc 100644 --- a/src/java/org/apache/poi/poifs/filesystem/POIFSFileSystem.java +++ b/src/java/org/apache/poi/poifs/filesystem/POIFSFileSystem.java @@ -32,7 +32,7 @@ import org.apache.poi.util.CloseIgnoringInputStream; */ public class POIFSFileSystem - extends OPOIFSFileSystem // TODO Temporary workaround during #56791 + extends NPOIFSFileSystem // TODO Temporary workaround during #56791 implements POIFSViewable { /** @@ -95,14 +95,14 @@ public class POIFSFileSystem * @param inp An InputStream which supports either mark/reset, or is a PushbackInputStream */ public static boolean hasPOIFSHeader(InputStream inp) throws IOException { - return OPOIFSFileSystem.hasPOIFSHeader(inp); + return NPOIFSFileSystem.hasPOIFSHeader(inp); } /** * Checks if the supplied first 8 bytes of a stream / file * has a POIFS (OLE2) header. */ public static boolean hasPOIFSHeader(byte[] header8Bytes) { - return OPOIFSFileSystem.hasPOIFSHeader(header8Bytes); + return NPOIFSFileSystem.hasPOIFSHeader(header8Bytes); } /** diff --git a/src/testcases/org/apache/poi/poifs/filesystem/TestDocumentInputStream.java b/src/testcases/org/apache/poi/poifs/filesystem/TestDocumentInputStream.java index 98b2b7a7d7..801935865c 100644 --- a/src/testcases/org/apache/poi/poifs/filesystem/TestDocumentInputStream.java +++ b/src/testcases/org/apache/poi/poifs/filesystem/TestDocumentInputStream.java @@ -31,10 +31,7 @@ import org.apache.poi.poifs.storage.RawDataBlock; /** * Class to test DocumentInputStream functionality - * - * @author Marc Johnson */ - public final class TestDocumentInputStream extends TestCase { private DocumentNode _workbook_n; private DocumentNode _workbook_o; @@ -95,7 +92,7 @@ public final class TestDocumentInputStream extends TestCase { * test constructor */ public void testConstructor() throws IOException { - DocumentInputStream ostream = new DocumentInputStream(_workbook_o); + DocumentInputStream ostream = new ODocumentInputStream(_workbook_o); DocumentInputStream nstream = new NDocumentInputStream(_workbook_n); assertEquals(_workbook_size, _workbook_o.getSize()); @@ -103,6 +100,9 @@ public final class TestDocumentInputStream extends TestCase { assertEquals(_workbook_size, ostream.available()); assertEquals(_workbook_size, nstream.available()); + + ostream.close(); + nstream.close(); } /** @@ -514,12 +514,14 @@ public final class TestDocumentInputStream extends TestCase { NPOIFSFileSystem npoifs = new NPOIFSFileSystem(sample); try { - POIFSFileSystem opoifs = new POIFSFileSystem(new FileInputStream(sample)); + OPOIFSFileSystem opoifs = new OPOIFSFileSystem(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(npoifs, npoifs.getRoot().getFileSystem()); + assertEquals(null, npoifs.getRoot().getOFileSystem()); + assertEquals(null, opoifs.getRoot().getFileSystem()); + assertEquals(opoifs, opoifs.getRoot().getOFileSystem()); assertEquals(null, opoifs.getRoot().getNFileSystem()); // Check inside