You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ki...@apache.org on 2018/08/26 11:55:02 UTC

svn commit: r1839201 [2/5] - in /poi: site/src/documentation/content/xdocs/ trunk/src/examples/src/org/apache/poi/hpsf/examples/ trunk/src/examples/src/org/apache/poi/poifs/poibrowser/ trunk/src/java/org/apache/poi/ trunk/src/java/org/apache/poi/extrac...

Modified: poi/trunk/src/java/org/apache/poi/poifs/eventfilesystem/POIFSReader.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/poifs/eventfilesystem/POIFSReader.java?rev=1839201&r1=1839200&r2=1839201&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/poifs/eventfilesystem/POIFSReader.java (original)
+++ poi/trunk/src/java/org/apache/poi/poifs/eventfilesystem/POIFSReader.java Sun Aug 26 11:55:00 2018
@@ -19,23 +19,19 @@
 
 package org.apache.poi.poifs.eventfilesystem;
 
-import java.io.FileInputStream;
+import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
-import java.util.Iterator;
 
 import org.apache.poi.poifs.filesystem.DocumentInputStream;
-import org.apache.poi.poifs.filesystem.OPOIFSDocument;
+import org.apache.poi.poifs.filesystem.NPOIFSDocument;
+import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
 import org.apache.poi.poifs.filesystem.POIFSDocumentPath;
 import org.apache.poi.poifs.property.DirectoryProperty;
+import org.apache.poi.poifs.property.DocumentProperty;
+import org.apache.poi.poifs.property.NPropertyTable;
 import org.apache.poi.poifs.property.Property;
-import org.apache.poi.poifs.property.PropertyTable;
 import org.apache.poi.poifs.property.RootProperty;
-import org.apache.poi.poifs.storage.BlockAllocationTableReader;
-import org.apache.poi.poifs.storage.BlockList;
-import org.apache.poi.poifs.storage.HeaderBlock;
-import org.apache.poi.poifs.storage.RawDataBlockList;
-import org.apache.poi.poifs.storage.SmallBlockTableReader;
 import org.apache.poi.util.IOUtils;
 
 /**
@@ -49,62 +45,54 @@ import org.apache.poi.util.IOUtils;
 
 public class POIFSReader
 {
-    private final POIFSReaderRegistry registry;
-    private boolean registryClosed;
+    private final POIFSReaderRegistry registry = new POIFSReaderRegistry();
+    private boolean registryClosed = false;
     private boolean notifyEmptyDirectories;
+//    private NPOIFSFileSystem poifs;
 
     /**
-     * Create a POIFSReader
+     * Read from an InputStream and process the documents we get
+     *
+     * @param stream the InputStream from which to read the data
+     *
+     * @exception IOException on errors reading, or on invalid data
      */
 
-    public POIFSReader()
-    {
-        registry       = new POIFSReaderRegistry();
-        registryClosed = false;
+    public void read(final InputStream stream) throws IOException {
+        try (NPOIFSFileSystem poifs = new NPOIFSFileSystem(stream)) {
+            read(poifs);
+        }
     }
 
     /**
-     * Read from an InputStream and process the documents we get
+     * Read from a File and process the documents we get
      *
-     * @param stream the InputStream from which to read the data
+     * @param poifsFile the file from which to read the data
      *
      * @exception IOException on errors reading, or on invalid data
      */
+    public void read(final File poifsFile) throws IOException {
+        try (NPOIFSFileSystem poifs = new NPOIFSFileSystem(poifsFile, true)) {
+            read(poifs);
+        }
+    }
 
-    public void read(final InputStream stream)
-        throws IOException
-    {
+    /**
+     * Read from a NPOIFSFileSystem and process the documents we get
+     *
+     * @param poifs the NPOIFSFileSystem from which to read the data
+     *
+     * @exception IOException on errors reading, or on invalid data
+     */
+    public void read(final NPOIFSFileSystem poifs) throws IOException {
         registryClosed = true;
 
-        // read the header block from the stream
-        HeaderBlock header_block = new HeaderBlock(stream);
-
-        // read the rest of the stream into blocks
-        RawDataBlockList data_blocks = new RawDataBlockList(stream, header_block.getBigBlockSize());
-
-        // set up the block allocation table (necessary for the
-        // data_blocks to be manageable
-        new BlockAllocationTableReader(header_block.getBigBlockSize(),
-                                       header_block.getBATCount(),
-                                       header_block.getBATArray(),
-                                       header_block.getXBATCount(),
-                                       header_block.getXBATIndex(),
-                                       data_blocks);
-
         // get property table from the document
-        PropertyTable properties =
-            new PropertyTable(header_block, data_blocks);
+        NPropertyTable properties = poifs.getPropertyTable();
 
         // process documents
         RootProperty root = properties.getRoot();
-        processProperties(SmallBlockTableReader
-            .getSmallDocumentBlocks(
-                  header_block.getBigBlockSize(),
-                  data_blocks, root,
-                  header_block.getSBATStart()
-            ),
-            data_blocks, root.getChildren(), new POIFSDocumentPath()
-        );
+        processProperties(poifs, root, new POIFSDocumentPath());
     }
 
     /**
@@ -117,14 +105,11 @@ public class POIFSReader
      *                                  called
      */
 
-    public void registerListener(final POIFSReaderListener listener)
-    {
-        if (listener == null)
-        {
+    public void registerListener(final POIFSReaderListener listener) {
+        if (listener == null) {
             throw new NullPointerException();
         }
-        if (registryClosed)
-        {
+        if (registryClosed) {
             throw new IllegalStateException();
         }
         registry.registerListener(listener);
@@ -143,9 +128,7 @@ public class POIFSReader
      *                                  called
      */
 
-    public void registerListener(final POIFSReaderListener listener,
-                                 final String name)
-    {
+    public void registerListener(final POIFSReaderListener listener, final String name) {
         registerListener(listener, null, name);
     }
 
@@ -166,19 +149,14 @@ public class POIFSReader
 
     public void registerListener(final POIFSReaderListener listener,
                                  final POIFSDocumentPath path,
-                                 final String name)
-    {
-        if ((listener == null) || (name == null) || (name.length() == 0))
-        {
+                                 final String name) {
+        if ((listener == null) || (name == null) || (name.length() == 0)) {
             throw new NullPointerException();
         }
-        if (registryClosed)
-        {
+        if (registryClosed) {
             throw new IllegalStateException();
         }
-        registry.registerListener(listener,
-                                  (path == null) ? new POIFSDocumentPath()
-                                                 : path, name);
+        registry.registerListener(listener, (path == null) ? new POIFSDocumentPath() : path, name);
     }
 
     /**
@@ -186,7 +164,7 @@ public class POIFSReader
      * If this flag is activated, the {@link POIFSReaderListener listener} receives
      * {@link POIFSReaderEvent POIFSReaderEvents} with nulled {@code name} and {@code stream}
      *
-     * @param notifyEmptyDirectories
+     * @param notifyEmptyDirectories if {@code true}, empty directories will be notified
      */
     public void setNotifyEmptyDirectories(boolean notifyEmptyDirectories) {
         this.notifyEmptyDirectories = notifyEmptyDirectories;
@@ -198,139 +176,72 @@ public class POIFSReader
      *
      * @param args names of the files
      *
-     * @exception IOException
+     * @exception IOException if the files can't be read or have invalid content
      */
 
-    public static void main(String args[])
-        throws IOException
-    {
-        if (args.length == 0)
-        {
+    public static void main(String args[]) throws IOException {
+        if (args.length == 0) {
             System.err.println("at least one argument required: input filename(s)");
             System.exit(1);
         }
 
         // register for all
-        for (String arg : args)
-        {
-            POIFSReader         reader   = new POIFSReader();
-            POIFSReaderListener listener = new SampleListener();
-
-            reader.registerListener(listener);
+        for (String arg : args) {
+            POIFSReader reader = new POIFSReader();
+            reader.registerListener(POIFSReader::readEntry);
             System.out.println("reading " + arg);
-            FileInputStream istream = new FileInputStream(arg);
 
-            reader.read(istream);
-            istream.close();
+            reader.read(new File(arg));
         }
     }
 
-    private void processProperties(final BlockList small_blocks,
-                                   final BlockList big_blocks,
-                                   final Iterator<Property> properties,
-                                   final POIFSDocumentPath path)
-    throws IOException {
-        if (!properties.hasNext() && notifyEmptyDirectories) {
-            Iterator<POIFSReaderListener> listeners  = registry.getListeners(path, ".");
-            while (listeners.hasNext()) {
-                POIFSReaderListener pl = listeners.next();
-                POIFSReaderEvent pe = new POIFSReaderEvent(null, path, null);
-                pl.processPOIFSReaderEvent(pe);
+    private static void readEntry(POIFSReaderEvent event) {
+        POIFSDocumentPath path = event.getPath();
+        StringBuilder sb = new StringBuilder();
+
+        try (DocumentInputStream istream = event.getStream()) {
+            sb.setLength(0);
+            int pathLength = path.length();
+            for (int k = 0; k < pathLength; k++) {
+                sb.append("/").append(path.getComponent(k));
             }
-            return;
+            byte[] data = IOUtils.toByteArray(istream);
+            sb.append("/").append(event.getName()).append(": ").append(data.length).append(" bytes read");
+            System.out.println(sb);
+        } catch (IOException ignored) {
         }
+    }
 
-        while (properties.hasNext())
-        {
-            Property property = properties.next();
-            String   name     = property.getName();
+    private void processProperties(final NPOIFSFileSystem poifs, DirectoryProperty dir, final POIFSDocumentPath path) {
+        boolean hasChildren = false;
+        for (final Property property : dir) {
+            hasChildren = true;
+            String name = property.getName();
 
             if (property.isDirectory()) {
                 POIFSDocumentPath new_path = new POIFSDocumentPath(path,new String[]{name});
-                DirectoryProperty dp = (DirectoryProperty) property;
-                processProperties(small_blocks, big_blocks, dp.getChildren(), new_path);
+                processProperties(poifs, (DirectoryProperty) property, new_path);
             } else {
-                int startBlock = property.getStartBlock();
-                Iterator<POIFSReaderListener> listeners  = registry.getListeners(path, name);
-
-                if (listeners.hasNext())
-                {
-                    int            size     = property.getSize();
-                    OPOIFSDocument document = null;
-
-                    if (property.shouldUseSmallBlocks())
-                    {
-                        document =
-                            new OPOIFSDocument(name, small_blocks
-                                .fetchBlocks(startBlock, -1), size);
+                NPOIFSDocument document = null;
+                for (POIFSReaderListener rl : registry.getListeners(path, name)) {
+                    if (document == null) {
+                        document = new NPOIFSDocument((DocumentProperty)property, poifs);
                     }
-                    else
-                    {
-                        document =
-                            new OPOIFSDocument(name, big_blocks
-                                .fetchBlocks(startBlock, -1), size);
-                    }
-                    while (listeners.hasNext())
-                    {
-                        POIFSReaderListener listener = listeners.next();
-                        try (DocumentInputStream dis = new DocumentInputStream(document)) {
-                            listener.processPOIFSReaderEvent(new POIFSReaderEvent(dis, path, name));
-                        }
-                    }
-                }
-                else
-                {
-
-                    // consume the document's data and discard it
-                    if (property.shouldUseSmallBlocks())
-                    {
-                        small_blocks.fetchBlocks(startBlock, -1);
-                    }
-                    else
-                    {
-                        big_blocks.fetchBlocks(startBlock, -1);
+                    try (DocumentInputStream dis = new DocumentInputStream(document)) {
+                        POIFSReaderEvent pe = new POIFSReaderEvent(dis, path, name);
+                        rl.processPOIFSReaderEvent(pe);
                     }
                 }
             }
         }
-    }
 
-    private static class SampleListener
-        implements POIFSReaderListener
-    {
-
-        /**
-         * Constructor SampleListener
-         */
-
-        SampleListener()
-        {
-        }
-
-        /**
-         * Method processPOIFSReaderEvent
-         *
-         * @param event
-         */
-
-        @Override
-        public void processPOIFSReaderEvent(final POIFSReaderEvent event) {
-            DocumentInputStream istream = event.getStream();
-            POIFSDocumentPath   path    = event.getPath();
-            String              name    = event.getName();
-
-            try {
-                byte[] data = IOUtils.toByteArray(istream);
-                int pathLength = path.length();
+        if (hasChildren || !notifyEmptyDirectories) {
+            return;
+        }
 
-                for (int k = 0; k < pathLength; k++) {
-                    System.out.print("/" + path.getComponent(k));
-                }
-                System.out.println("/" + name + ": " + data.length + " bytes read");
-            } catch (IOException ignored) {
-            } finally {
-                IOUtils.closeQuietly(istream);
-            }
+        for (POIFSReaderListener rl : registry.getListeners(path, ".")) {
+            POIFSReaderEvent pe = new POIFSReaderEvent(null, path, null);
+            rl.processPOIFSReaderEvent(pe);
         }
     }
 }

Modified: poi/trunk/src/java/org/apache/poi/poifs/eventfilesystem/POIFSReaderRegistry.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/poifs/eventfilesystem/POIFSReaderRegistry.java?rev=1839201&r1=1839200&r2=1839201&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/poifs/eventfilesystem/POIFSReaderRegistry.java (original)
+++ poi/trunk/src/java/org/apache/poi/poifs/eventfilesystem/POIFSReaderRegistry.java Sun Aug 26 11:55:00 2018
@@ -79,34 +79,21 @@ class POIFSReaderRegistry
 
             // not an omnivorous listener (if it was, this method is a
             // no-op)
-            Set<DocumentDescriptor> descriptors = selectiveListeners.get(listener);
+            Set<DocumentDescriptor> descriptors =
+                    selectiveListeners.computeIfAbsent(listener, k -> new HashSet<>());
 
-            if (descriptors == null)
-            {
+            // this listener has not registered before
+            DocumentDescriptor descriptor = new DocumentDescriptor(path, documentName);
 
-                // this listener has not registered before
-                descriptors = new HashSet<>();
-                selectiveListeners.put(listener, descriptors);
-            }
-            DocumentDescriptor descriptor = new DocumentDescriptor(path,
-                                                documentName);
-
-            if (descriptors.add(descriptor))
-            {
+            if (descriptors.add(descriptor)) {
 
                 // this listener wasn't already listening for this
                 // document -- add the listener to the set of
                 // listeners for this document
                 Set<POIFSReaderListener> listeners =
-                    chosenDocumentDescriptors.get(descriptor);
-
-                if (listeners == null)
-                {
+                        chosenDocumentDescriptors.computeIfAbsent(descriptor, k -> new HashSet<>());
 
-                    // nobody was listening for this document before
-                    listeners = new HashSet<>();
-                    chosenDocumentDescriptors.put(descriptor, listeners);
-                }
+                // nobody was listening for this document before
                 listeners.add(listener);
             }
         }
@@ -141,7 +128,7 @@ class POIFSReaderRegistry
      * @return an Iterator POIFSReaderListeners; may be empty
      */
 
-    Iterator<POIFSReaderListener> getListeners(final POIFSDocumentPath path, final String name)
+    Iterable<POIFSReaderListener> getListeners(final POIFSDocumentPath path, final String name)
     {
         Set<POIFSReaderListener> rval = new HashSet<>(omnivorousListeners);
         Set<POIFSReaderListener> selectiveListenersInner =
@@ -151,20 +138,16 @@ class POIFSReaderRegistry
         {
             rval.addAll(selectiveListenersInner);
         }
-        return rval.iterator();
+        return rval;
     }
 
     private void removeSelectiveListener(final POIFSReaderListener listener)
     {
         Set<DocumentDescriptor> selectedDescriptors = selectiveListeners.remove(listener);
 
-        if (selectedDescriptors != null)
-        {
-            Iterator<DocumentDescriptor> iter = selectedDescriptors.iterator();
-
-            while (iter.hasNext())
-            {
-                dropDocument(listener, iter.next());
+        if (selectedDescriptors != null) {
+            for (DocumentDescriptor selectedDescriptor : selectedDescriptors) {
+                dropDocument(listener, selectedDescriptor);
             }
         }
     }

Copied: poi/trunk/src/java/org/apache/poi/poifs/eventfilesystem/package-info.java (from r1839200, poi/trunk/src/java/org/apache/poi/poifs/eventfilesystem/package.html)
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/poifs/eventfilesystem/package-info.java?p2=poi/trunk/src/java/org/apache/poi/poifs/eventfilesystem/package-info.java&p1=poi/trunk/src/java/org/apache/poi/poifs/eventfilesystem/package.html&r1=1839200&r2=1839201&rev=1839201&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/poifs/eventfilesystem/package.html (original)
+++ poi/trunk/src/java/org/apache/poi/poifs/eventfilesystem/package-info.java Sun Aug 26 11:55:00 2018
@@ -1,6 +1,4 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
-<!--
-   ====================================================================
+/* ====================================================================
    Licensed to the Apache Software Foundation (ASF) under one or more
    contributor license agreements.  See the NOTICE file distributed with
    this work for additional information regarding copyright ownership.
@@ -15,23 +13,11 @@
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
-   ====================================================================
--->
-<html>
-<head>
-</head>
-<body bgcolor="white">
+==================================================================== */
 
-The eventfilesystem is an efficient method for reading OLE 2 CDF files.  It is to OLE 2 CDF what SAX is to XML.
-
-<h2>Related Documentation</h2>
-
-For overviews, tutorials, examples, guides, and tool documentation, please see:
-<ul>
-<li><a href="http://poi.apache.org">Apache POI Project</a>
-</ul>
-
-<!-- Put @see and @since tags down here. -->
-@see org.apache.poi.poifs.filesystem
-</body>
-</html>
+/**
+ * The eventfilesystem is an efficient method for reading OLE 2 CDF files.  It is to OLE 2 CDF what SAX is to XML.
+ *
+ * @see org.apache.poi.poifs.filesystem
+ */
+package org.apache.poi.poifs.eventfilesystem;
\ No newline at end of file

Modified: poi/trunk/src/java/org/apache/poi/poifs/filesystem/DirectoryNode.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/poifs/filesystem/DirectoryNode.java?rev=1839201&r1=1839200&r2=1839201&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/poifs/filesystem/DirectoryNode.java (original)
+++ poi/trunk/src/java/org/apache/poi/poifs/filesystem/DirectoryNode.java Sun Aug 26 11:55:00 2018
@@ -44,33 +44,16 @@ public class DirectoryNode
 {
 
     // Map of Entry instances, keyed by their names
-    private Map<String,Entry> _byname;
+    private final Map<String,Entry> _byname = new HashMap<>();
+
     // Our list of entries, kept sorted to preserve order
-    private ArrayList<Entry> _entries;
+    private final ArrayList<Entry> _entries = new ArrayList<>();
 
-    // Only one of these two will exist
-    // the OPOIFSFileSystem we belong to
-    private OPOIFSFileSystem   _ofilesystem;
     // the NPOIFSFileSytem we belong to
-    private NPOIFSFileSystem  _nfilesystem;
+    private final NPOIFSFileSystem  _nfilesystem;
 
     // the path described by this document
-    private POIFSDocumentPath _path;
-
-    /**
-     * create a DirectoryNode. This method is not public by design; it
-     * is intended strictly for the internal use of this package
-     *
-     * @param property the DirectoryProperty for this DirectoryEntry
-     * @param filesystem the OPOIFSFileSystem we belong to
-     * @param parent the parent of this entry
-     */
-    DirectoryNode(final DirectoryProperty property,
-                  final OPOIFSFileSystem filesystem,
-                  final DirectoryNode parent)
-    {
-       this(property, parent, filesystem, null);
-    }
+    private final POIFSDocumentPath _path;
 
     /**
      * create a DirectoryNode. This method is not public by design; it
@@ -84,16 +67,7 @@ public class DirectoryNode
                   final NPOIFSFileSystem nfilesystem,
                   final DirectoryNode parent)
     {
-       this(property, parent, null, nfilesystem);
-    }
-
-    private DirectoryNode(final DirectoryProperty property,
-                          final DirectoryNode parent,
-                          final OPOIFSFileSystem ofilesystem,
-                          final NPOIFSFileSystem nfilesystem)
-    {
         super(property, parent);
-        this._ofilesystem = ofilesystem;
         this._nfilesystem = nfilesystem;
 
         if (parent == null)
@@ -103,12 +77,10 @@ public class DirectoryNode
         else
         {
             _path = new POIFSDocumentPath(parent._path, new String[]
-            {
-                property.getName()
-            });
+                    {
+                            property.getName()
+                    });
         }
-        _byname     = new HashMap<>();
-        _entries    = new ArrayList<>();
         Iterator<Property> iter = property.getChildren();
 
         while (iter.hasNext())
@@ -119,11 +91,7 @@ public class DirectoryNode
             if (child.isDirectory())
             {
                 DirectoryProperty childDir = (DirectoryProperty) child;
-                if(_ofilesystem != null) {
-                   childNode = new DirectoryNode(childDir, _ofilesystem, this);
-                } else {
-                   childNode = new DirectoryNode(childDir, _nfilesystem, this);
-                }
+                childNode = new DirectoryNode(childDir, _nfilesystem, this);
             }
             else
             {
@@ -151,15 +119,6 @@ public class DirectoryNode
         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()
-    {
-        return _ofilesystem;
-    }
 
     /**
      * If this is NPOIFS based, return the NPOIFSFileSystem
@@ -218,30 +177,7 @@ public class DirectoryNode
      *
      * @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;
-    }
-
-    /**
-     * create a new DocumentEntry
-     *
-     * @param document the new document
-     *
-     * @return the new DocumentEntry
-     *
-     * @exception IOException
+     * @exception IOException if the document can't be created
      */
     DocumentEntry createDocument(final NPOIFSDocument document)
         throws IOException
@@ -302,14 +238,11 @@ public class DirectoryNode
             _entries.remove(entry);
             _byname.remove(entry.getName());
 
-            if(_ofilesystem != null) {
-                _ofilesystem.remove(entry);
-            } else {
-                try {
-                    _nfilesystem.remove(entry);
-                } catch (IOException e) {
-                    // TODO Work out how to report this, given we can't change the method signature...
-                }
+            try {
+                _nfilesystem.remove(entry);
+            } catch (IOException e) {
+                // TODO Work out how to report this, given we can't change the method signature...
+                throw new RuntimeException(e);
             }
         }
         return rval;
@@ -411,18 +344,14 @@ public class DirectoryNode
      *
      * @return the new DocumentEntry
      *
-     * @exception IOException
+     * @exception IOException if the document can't be created
      */
 
     public DocumentEntry createDocument(final String name,
                                         final InputStream stream)
         throws IOException
     {
-        if(_nfilesystem != null) {
-           return createDocument(new NPOIFSDocument(name, _nfilesystem, stream));
-        } else {
-           return createDocument(new OPOIFSDocument(name, stream));
-        }
+        return createDocument(new NPOIFSDocument(name, _nfilesystem, stream));
     }
 
     /**
@@ -434,18 +363,14 @@ public class DirectoryNode
      *
      * @return the new DocumentEntry
      *
-     * @exception IOException
+     * @exception IOException if the document can't be created
      */
 
     public DocumentEntry createDocument(final String name, final int size,
                                         final POIFSWriterListener writer)
         throws IOException
     {
-        if(_nfilesystem != null) {
-            return createDocument(new NPOIFSDocument(name, size, _nfilesystem, writer));
-         } else {
-            return createDocument(new OPOIFSDocument(name, size, _path, writer));
-         }
+        return createDocument(new NPOIFSDocument(name, size, _nfilesystem, writer));
     }
 
     /**
@@ -455,22 +380,16 @@ public class DirectoryNode
      *
      * @return the new DirectoryEntry
      *
-     * @exception IOException
+     * @exception IOException if the directory can't be created
      */
 
     public DirectoryEntry createDirectory(final String name)
         throws IOException
     {
-        DirectoryNode rval;
         DirectoryProperty property = new DirectoryProperty(name);
 
-        if(_ofilesystem != null) {
-           rval = new DirectoryNode(property, _ofilesystem, this);
-           _ofilesystem.addDirectory(property);
-        } else {
-           rval = new DirectoryNode(property, _nfilesystem, this);
-           _nfilesystem.addDirectory(property);
-        }
+        DirectoryNode rval = new DirectoryNode(property, _nfilesystem, this);
+       _nfilesystem.addDirectory(property);
 
         (( DirectoryProperty ) getProperty()).addChild(property);
         _entries.add(rval);
@@ -487,9 +406,9 @@ public class DirectoryNode
      *
      * @return the new or updated DocumentEntry
      *
-     * @exception IOException
+     * @exception IOException if the document can't be created or its content be replaced
      */
-
+    @SuppressWarnings("WeakerAccess")
     public DocumentEntry createOrUpdateDocument(final String name,
                                                 final InputStream stream)
         throws IOException
@@ -498,15 +417,9 @@ public class DirectoryNode
             return createDocument(name, stream);
         } else {
             DocumentNode existing = (DocumentNode)getEntry(name);
-            if (_nfilesystem != null) {
-                NPOIFSDocument nDoc = new NPOIFSDocument(existing);
-                nDoc.replaceContents(stream);
-                return existing;
-            } else {
-                // Do it the hard way for Old POIFS...
-                deleteEntry(existing);
-                return createDocument(name, stream);
-            }
+            NPOIFSDocument nDoc = new NPOIFSDocument(existing);
+            nDoc.replaceContents(stream);
+            return existing;
         }
     }
     

Modified: poi/trunk/src/java/org/apache/poi/poifs/filesystem/DocumentInputStream.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/poifs/filesystem/DocumentInputStream.java?rev=1839201&r1=1839200&r2=1839201&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/poifs/filesystem/DocumentInputStream.java (original)
+++ poi/trunk/src/java/org/apache/poi/poifs/filesystem/DocumentInputStream.java Sun Aug 26 11:55:00 2018
@@ -20,7 +20,6 @@ package org.apache.poi.poifs.filesystem;
 import java.io.IOException;
 import java.io.InputStream;
 
-import org.apache.poi.util.IOUtils;
 import org.apache.poi.util.LittleEndianInput;
 import org.apache.poi.util.SuppressForbidden;
 
@@ -34,10 +33,6 @@ public class DocumentInputStream extends
 	/** returned by read operations if we're at end of document */
 	protected static final int EOF = -1;
 
-	protected static final int SIZE_SHORT = 2;
-	protected static final int SIZE_INT = 4;
-	protected static final int SIZE_LONG = 8;
-	
 	private DocumentInputStream delegate;
 	
 	/** For use by downstream implementations */
@@ -55,27 +50,7 @@ public class DocumentInputStream extends
 	   if (!(document instanceof DocumentNode)) {
 	      throw new IOException("Cannot open internal document storage");
 	   }
-	   DocumentNode documentNode = (DocumentNode)document;
-	   DirectoryNode parentNode = (DirectoryNode)document.getParent();
-
-	   if(documentNode.getDocument() != null) {
-	      delegate = new ODocumentInputStream(document);
-	   } else if(parentNode.getOFileSystem() != null) {
-	      delegate = new ODocumentInputStream(document);
-	   } else if(parentNode.getNFileSystem() != null) {
-	      delegate = new NDocumentInputStream(document);
-	   } else {
-	      throw new IOException("No FileSystem bound on the parent, can't read contents");
-	   }
-	}
-
-	/**
-	 * Create an InputStream from the specified Document
-	 * 
-	 * @param document the Document to be read
-	 */
-	public DocumentInputStream(OPOIFSDocument document) {
-	   delegate = new ODocumentInputStream(document);
+	   delegate = new NDocumentInputStream(document);
 	}
 
    /**

Modified: poi/trunk/src/java/org/apache/poi/poifs/filesystem/DocumentNode.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/poifs/filesystem/DocumentNode.java?rev=1839201&r1=1839200&r2=1839201&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/poifs/filesystem/DocumentNode.java (original)
+++ poi/trunk/src/java/org/apache/poi/poifs/filesystem/DocumentNode.java Sun Aug 26 11:55:00 2018
@@ -35,7 +35,7 @@ public class DocumentNode
 {
 
     // underlying POIFSDocument instance
-    private OPOIFSDocument _document;
+    private NPOIFSDocument _document;
 
     /**
      * create a DocumentNode. This method is not public by design; it
@@ -56,7 +56,7 @@ public class DocumentNode
      *
      * @return the internal POIFSDocument
      */
-    OPOIFSDocument getDocument()
+    NPOIFSDocument getDocument()
     {
         return _document;
     }

Modified: poi/trunk/src/java/org/apache/poi/poifs/filesystem/EntryUtils.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/poifs/filesystem/EntryUtils.java?rev=1839201&r1=1839200&r2=1839201&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/poifs/filesystem/EntryUtils.java (original)
+++ poi/trunk/src/java/org/apache/poi/poifs/filesystem/EntryUtils.java Sun Aug 26 11:55:00 2018
@@ -16,27 +16,31 @@
 ==================================================================== */
 package org.apache.poi.poifs.filesystem;
 
-import java.io.FileNotFoundException;
+import java.io.EOFException;
 import java.io.IOException;
-import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
-
+import java.util.Objects;
+import java.util.stream.Collectors;
+import java.util.stream.StreamSupport;
+
+import org.apache.poi.hpsf.MarkUnsupportedException;
+import org.apache.poi.hpsf.NoPropertySetStreamException;
+import org.apache.poi.hpsf.PropertySet;
+import org.apache.poi.hpsf.PropertySetFactory;
 import org.apache.poi.util.Internal;
 
 @Internal
-public class EntryUtils
-{
+public final class EntryUtils {
+    private EntryUtils() {}
 
     /**
      * Copies an Entry into a target POIFS directory, recursively
      */
     @Internal
     public static void copyNodeRecursively( Entry entry, DirectoryEntry target )
-            throws IOException {
-        // logger.log( POILogger.ERROR, "copyNodeRecursively called with "+entry.getName()+
-        // ","+target.getName());
+    throws IOException {
         if ( entry.isDirectoryEntry() ) {
         	DirectoryEntry dirEntry = (DirectoryEntry)entry;
             DirectoryEntry newTarget = target.createDirectory( entry.getName() );
@@ -62,8 +66,8 @@ public class EntryUtils
      * @param targetRoot
      *            is the target Directory to copy to
      */
-    public static void copyNodes(DirectoryEntry sourceRoot,
-            DirectoryEntry targetRoot) throws IOException {
+    public static void copyNodes(DirectoryEntry sourceRoot, DirectoryEntry targetRoot)
+    throws IOException {
         for (Entry entry : sourceRoot) {
             copyNodeRecursively( entry, targetRoot );
         }
@@ -77,22 +81,8 @@ public class EntryUtils
      * @param target
      *            is the target POIFS to copy to
      */
-    public static void copyNodes( OPOIFSFileSystem source,
-            OPOIFSFileSystem target ) throws IOException
-    {
-        copyNodes( source.getRoot(), target.getRoot() );
-    }
-    /**
-     * Copies all nodes from one POIFS to the other
-     * 
-     * @param source
-     *            is the source POIFS to copy from
-     * @param target
-     *            is the target POIFS to copy to
-     */
-    public static void copyNodes( NPOIFSFileSystem source,
-            NPOIFSFileSystem target ) throws IOException
-    {
+    public static void copyNodes( NPOIFSFileSystem source, NPOIFSFileSystem target )
+    throws IOException {
         copyNodes( source.getRoot(), target.getRoot() );
     }
     
@@ -106,27 +96,8 @@ public class EntryUtils
      * @param target is the target POIFS to copy to
      * @param excepts is a list of Entry Names to be excluded from the copy
      */
-    public static void copyNodes( OPOIFSFileSystem source,
-            OPOIFSFileSystem target, List<String> excepts ) throws IOException
-    {
-        copyNodes(
-              new FilteringDirectoryNode(source.getRoot(), excepts),
-              new FilteringDirectoryNode(target.getRoot(), excepts)
-        );
-    }
-    /**
-     * Copies nodes from one POIFS to the other, minus the excepts.
-     * This delegates the filtering work to {@link FilteringDirectoryNode},
-     *  so excepts can be of the form "NodeToExclude" or
-     *  "FilteringDirectory/ExcludedChildNode"
-     * 
-     * @param source is the source POIFS to copy from
-     * @param target is the target POIFS to copy to
-     * @param excepts is a list of Entry Names to be excluded from the copy
-     */
-    public static void copyNodes( NPOIFSFileSystem source,
-            NPOIFSFileSystem target, List<String> excepts ) throws IOException
-    {
+    public static void copyNodes( NPOIFSFileSystem source, NPOIFSFileSystem target, List<String> excepts )
+    throws IOException {
         copyNodes(
               new FilteringDirectoryNode(source.getRoot(), excepts),
               new FilteringDirectoryNode(target.getRoot(), excepts)
@@ -142,114 +113,137 @@ public class EntryUtils
      *  use a {@link FilteringDirectoryNode}
      */
     public static boolean areDirectoriesIdentical(DirectoryEntry dirA, DirectoryEntry dirB) {
-       // First, check names
-       if (! dirA.getName().equals(dirB.getName())) {
-          return false;
-       }
-       
-       // Next up, check they have the same number of children
-       if (dirA.getEntryCount() != dirB.getEntryCount()) {
-          return false;
-       }
-       
-       // Next, check entries and their types/sizes
-       Map<String,Integer> aSizes = new HashMap<>();
-       final int isDirectory = -12345; 
-       for (Entry a : dirA) {
-          String aName = a.getName();
-          if (a.isDirectoryEntry()) {
-             aSizes.put(aName, isDirectory);
-          } else {
-             aSizes.put(aName, ((DocumentNode)a).getSize());
-          }
-       }
-       for (Entry b : dirB) {
-          String bName = b.getName();
-          if (! aSizes.containsKey(bName)) {
-             // In B but not A
-             return false;
-          }
-          
-          int size;
-          if (b.isDirectoryEntry()) {
-             size = isDirectory;
-          } else {
-             size = ((DocumentNode)b).getSize();
-          }
-          if (size != aSizes.get(bName)) {
-             // Either the wrong type, or they're different sizes
-             return false;
-          }
-          
-          // Track it as checked
-          aSizes.remove(bName);
-       }
-       if (!aSizes.isEmpty()) {
-          // Nodes were in A but not B
-          return false;
-       }
-       
-       // If that passed, check entry contents
-       for (Entry a : dirA) {
-          try {
-             Entry b = dirB.getEntry(a.getName());
-             boolean match;
-             if (a.isDirectoryEntry()) {
-                match = areDirectoriesIdentical(
-                      (DirectoryEntry)a, (DirectoryEntry)b);
-             } else {
-                match = areDocumentsIdentical(
-                      (DocumentEntry)a, (DocumentEntry)b);
-             }
-             if (!match) return false;
-          } catch(FileNotFoundException e) {
-             // Shouldn't really happen...
-             return false;
-          } catch(IOException e) {
-             // Something's messed up with one document, not a match
-             return false;
-          }
-       }
-       
-       // If we get here, they match!
-       return true;
+        return new DirectoryDelegate(dirA).equals(new DirectoryDelegate(dirB));
     }
     
     /**
-     * Checks to see if two Documents have the same name
-     *  and the same contents. (Their parent directories are
-     *  not checked)
-     */
-    public static boolean areDocumentsIdentical(DocumentEntry docA, DocumentEntry docB) throws IOException {
-       if (! docA.getName().equals(docB.getName())) {
-          // Names don't match, not the same
-          return false;
-       }
-       if (docA.getSize() != docB.getSize()) {
-          // Wrong sizes, can't have the same contents
-          return false;
-       }
-
-       boolean matches = true;
-       DocumentInputStream inpA = null, inpB = null;
-       try {
-          inpA = new DocumentInputStream(docA);
-          inpB = new DocumentInputStream(docB);
-          
-          int readA, readB;
-          do {
-             readA = inpA.read();
-             readB = inpB.read();
-             if (readA != readB) {
-                matches = false;
-                break;
-             }
-          } while(readA != -1 && readB != -1);
-       } finally {
-          if (inpA != null) inpA.close();
-          if (inpB != null) inpB.close();
-       }
-       
-       return matches;
+     * Compares two {@link DocumentEntry} instances of a POI file system.
+     * Documents that are not property set streams must be bitwise identical.
+     * Property set streams must be logically equal.<p>
+     *
+     * (Their parent directories are not checked)
+     */
+    @SuppressWarnings("WeakerAccess")
+    public static boolean areDocumentsIdentical(DocumentEntry docA, DocumentEntry docB)
+    throws IOException {
+        try {
+            return new DocumentDelegate(docA).equals(new DocumentDelegate(docB));
+        } catch (RuntimeException e) {
+            if (e.getCause() instanceof IOException) {
+                throw (IOException)e.getCause();
+            } else {
+                throw e;
+            }
+        }
+    }
+
+    private interface POIDelegate {
+    }
+
+    private static class DirectoryDelegate implements POIDelegate {
+        final DirectoryEntry dir;
+
+        DirectoryDelegate(DirectoryEntry dir) {
+            this.dir = dir;
+        }
+
+        private Map<String,POIDelegate> entries() {
+            return StreamSupport.stream(dir.spliterator(), false)
+                .collect(Collectors.toMap(Entry::getName, DirectoryDelegate::toDelegate));
+        }
+
+        private static POIDelegate toDelegate(Entry entry) {
+            return (entry.isDirectoryEntry())
+                ? new DirectoryDelegate((DirectoryEntry)entry)
+                : new DocumentDelegate((DocumentEntry)entry);
+        }
+
+        @Override
+        public boolean equals(Object other) {
+            if (!(other instanceof DirectoryDelegate)) {
+                return false;
+            }
+
+            DirectoryDelegate dd = (DirectoryDelegate)other;
+
+            if (this == dd) {
+                return true;
+            }
+
+            // First, check names
+            if (!Objects.equals(dir.getName(),dd.dir.getName())) {
+                return false;
+            }
+
+            // Next up, check they have the same number of children
+            if (dir.getEntryCount() != dd.dir.getEntryCount()) {
+                return false;
+            }
+
+            return entries().equals(dd.entries());
+        }
+    }
+
+    private static class DocumentDelegate implements POIDelegate {
+        final DocumentEntry doc;
+
+        DocumentDelegate(DocumentEntry doc) {
+            this.doc = doc;
+        }
+
+        @Override
+        public boolean equals(Object other) {
+            if (!(other instanceof DocumentDelegate)) {
+                return false;
+            }
+
+            DocumentDelegate dd = (DocumentDelegate)other;
+
+            if (this == dd) {
+                return true;
+            }
+
+
+            if (!Objects.equals(doc.getName(), dd.doc.getName())) {
+                // Names don't match, not the same
+                return false;
+            }
+
+            try (DocumentInputStream inpA = new DocumentInputStream(doc);
+                 DocumentInputStream inpB = new DocumentInputStream(dd.doc)) {
+
+                if (PropertySet.isPropertySetStream(inpA) &&
+                        PropertySet.isPropertySetStream(inpB)) {
+                    final PropertySet ps1 = PropertySetFactory.create(inpA);
+                    final PropertySet ps2 = PropertySetFactory.create(inpB);
+                    return ps1.equals(ps2);
+                } else {
+                    return isEqual(inpA, inpB);
+                }
+            } catch (MarkUnsupportedException | NoPropertySetStreamException | IOException ex) {
+                throw new RuntimeException(ex);
+            }
+        }
+
+        private static boolean isEqual(DocumentInputStream i1, DocumentInputStream i2)
+        throws IOException {
+            final byte[] buf1 = new byte[4*1024];
+            final byte[] buf2 = new byte[4*1024];
+            try {
+                int len;
+                while ((len = i1.read(buf1)) > 0) {
+                    i2.readFully(buf2,0,len);
+                    for(int i=0;i<len;i++) {
+                        if (buf1[i] != buf2[i]) {
+                            return false;
+                        }
+                    }
+                }
+                // is the end of the second file also.
+                return i2.read() < 0;
+            } catch(EOFException | RuntimeException ioe) {
+                return false;
+            }
+        }
     }
 }

Modified: poi/trunk/src/java/org/apache/poi/poifs/filesystem/NDocumentInputStream.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/poifs/filesystem/NDocumentInputStream.java?rev=1839201&r1=1839200&r2=1839201&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/poifs/filesystem/NDocumentInputStream.java (original)
+++ poi/trunk/src/java/org/apache/poi/poifs/filesystem/NDocumentInputStream.java Sun Aug 26 11:55:00 2018
@@ -17,6 +17,10 @@
 
 package org.apache.poi.poifs.filesystem;
 
+import static org.apache.poi.util.LittleEndianConsts.INT_SIZE;
+import static org.apache.poi.util.LittleEndianConsts.LONG_SIZE;
+import static org.apache.poi.util.LittleEndianConsts.SHORT_SIZE;
+
 import java.io.IOException;
 import java.nio.ByteBuffer;
 import java.util.Iterator;
@@ -71,9 +75,9 @@ public final class NDocumentInputStream
         _document_size = document.getSize();
         _closed = false;
 
-        if (_document_size < 0) {
-            //throw new RecordFormatException("Document size can't be < 0");
-        }
+        // can't be asserted ... see bug 61300
+        // assert (_document_size >= 0) : "Document size can't be < 0";
+
         DocumentNode doc = (DocumentNode)document;
         DocumentProperty property = (DocumentProperty)doc.getProperty();
         _document = new NPOIFSDocument(
@@ -284,33 +288,33 @@ public final class NDocumentInputStream
 
    @Override
 	public long readLong() {
-		checkAvaliable(SIZE_LONG);
-		byte[] data = new byte[SIZE_LONG];
-		readFully(data, 0, SIZE_LONG);
+		checkAvaliable(LONG_SIZE);
+		byte[] data = new byte[LONG_SIZE];
+		readFully(data, 0, LONG_SIZE);
 		return LittleEndian.getLong(data, 0);
 	}
 
    @Override
    public short readShort() {
-      checkAvaliable(SIZE_SHORT);
-      byte[] data = new byte[SIZE_SHORT];
-      readFully(data, 0, SIZE_SHORT);
+      checkAvaliable(SHORT_SIZE);
+      byte[] data = new byte[SHORT_SIZE];
+      readFully(data, 0, SHORT_SIZE);
       return LittleEndian.getShort(data);
    }
 
    @Override
 	public int readInt() {
-		checkAvaliable(SIZE_INT);
-      byte[] data = new byte[SIZE_INT];
-      readFully(data, 0, SIZE_INT);
+		checkAvaliable(INT_SIZE);
+      byte[] data = new byte[INT_SIZE];
+      readFully(data, 0, INT_SIZE);
       return LittleEndian.getInt(data);
 	}
 
    @Override
 	public int readUShort() {
-		checkAvaliable(SIZE_SHORT);
-      byte[] data = new byte[SIZE_SHORT];
-      readFully(data, 0, SIZE_SHORT);
+		checkAvaliable(SHORT_SIZE);
+      byte[] data = new byte[SHORT_SIZE];
+      readFully(data, 0, SHORT_SIZE);
       return LittleEndian.getUShort(data);
 	}
 

Modified: poi/trunk/src/java/org/apache/poi/poifs/filesystem/NPOIFSDocument.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/poifs/filesystem/NPOIFSDocument.java?rev=1839201&r1=1839200&r2=1839201&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/poifs/filesystem/NPOIFSDocument.java (original)
+++ poi/trunk/src/java/org/apache/poi/poifs/filesystem/NPOIFSDocument.java Sun Aug 26 11:55:00 2018
@@ -17,6 +17,8 @@
 
 package org.apache.poi.poifs.filesystem;
 
+import static java.util.Collections.emptyList;
+
 import java.io.BufferedInputStream;
 import java.io.IOException;
 import java.io.InputStream;
@@ -25,7 +27,6 @@ import java.nio.ByteBuffer;
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.Iterator;
-import java.util.List;
 
 import org.apache.poi.poifs.common.POIFSConstants;
 import org.apache.poi.poifs.dev.POIFSViewable;
@@ -37,7 +38,7 @@ import org.apache.poi.util.IOUtils;
  * This class manages a document in the NIO POIFS filesystem.
  * This is the {@link NPOIFSFileSystem} version.
  */
-public final class NPOIFSDocument implements POIFSViewable {
+public final class NPOIFSDocument implements POIFSViewable, Iterable<ByteBuffer> {
 
     //arbitrarily selected; may need to increase
     private static final int MAX_RECORD_LENGTH = 100_000;
@@ -51,7 +52,7 @@ public final class NPOIFSDocument implem
    /**
     * Constructor for an existing Document 
     */
-   public NPOIFSDocument(DocumentNode document) throws IOException {
+   public NPOIFSDocument(DocumentNode document) {
        this((DocumentProperty)document.getProperty(), 
             ((DirectoryNode)document.getParent()).getNFileSystem());
    }
@@ -59,9 +60,7 @@ public final class NPOIFSDocument implem
    /**
     * Constructor for an existing Document 
     */
-   public NPOIFSDocument(DocumentProperty property, NPOIFSFileSystem filesystem) 
-      throws IOException
-   {
+   public NPOIFSDocument(DocumentProperty property, NPOIFSFileSystem filesystem) {
       this._property = property;
       this._filesystem = filesystem;
 
@@ -90,7 +89,8 @@ public final class NPOIFSDocument implem
 
       // Build the property for it
       this._property = new DocumentProperty(name, length);
-      _property.setStartBlock(_stream.getStartBlock());     
+      _property.setStartBlock(_stream.getStartBlock());
+      _property.setDocument(this);
    }
    
    public NPOIFSDocument(String name, int size, NPOIFSFileSystem filesystem, POIFSWriterListener writer) 
@@ -116,7 +116,8 @@ public final class NPOIFSDocument implem
 
        // And build the property for it
        this._property = new DocumentProperty(name, size);
-       _property.setStartBlock(_stream.getStartBlock());     
+       _property.setStartBlock(_stream.getStartBlock());
+       _property.setDocument(this);
    }
    
    /**
@@ -128,7 +129,8 @@ public final class NPOIFSDocument implem
        bis.mark(bigBlockSize);
 
        // Do we need to store as a mini stream or a full one?
-       if(bis.skip(bigBlockSize) < bigBlockSize) {
+       long streamBlockSize = IOUtils.skipFully(bis, bigBlockSize);
+       if (streamBlockSize < bigBlockSize) {
           _stream = new NPOIFSStream(_filesystem.getMiniStore());
           _block_size = _filesystem.getMiniStore().getBlockStoreBlockSize();
        } else {
@@ -140,26 +142,21 @@ public final class NPOIFSDocument implem
        bis.reset();
        
        // Store it
-       OutputStream os = _stream.getOutputStream();
-       byte buf[] = new byte[1024];
-       int length = 0;
-       
-       for (int readBytes; (readBytes = bis.read(buf)) != -1; length += readBytes) {
-           os.write(buf, 0, readBytes);
+       final long length;
+       try (OutputStream os = _stream.getOutputStream()) {
+           length = IOUtils.copy(bis, os);
+
+           // Pad to the end of the block with -1s
+           int usedInBlock = (int) (length % _block_size);
+           if (usedInBlock != 0 && usedInBlock != _block_size) {
+               int toBlockEnd = _block_size - usedInBlock;
+               byte[] padding = IOUtils.safelyAllocate(toBlockEnd, MAX_RECORD_LENGTH);
+               Arrays.fill(padding, (byte) 0xFF);
+               os.write(padding);
+           }
        }
-       
-       // Pad to the end of the block with -1s
-       int usedInBlock = length % _block_size;
-       if (usedInBlock != 0 && usedInBlock != _block_size) {
-           int toBlockEnd = _block_size - usedInBlock;
-           byte[] padding = IOUtils.safelyAllocate(toBlockEnd, MAX_RECORD_LENGTH);
-           Arrays.fill(padding, (byte)0xFF);
-           os.write(padding);
-       }
-       
-       // Tidy and return the length
-       os.close();
-       return length;
+
+       return (int)length;
    }
    
    /**
@@ -178,15 +175,15 @@ public final class NPOIFSDocument implem
    int getDocumentBlockSize() {
       return _block_size;
    }
-   
-   Iterator<ByteBuffer> getBlockIterator() {
-      if(getSize() > 0) {
-         return _stream.getBlockIterator();
-      } else {
-         List<ByteBuffer> empty = Collections.emptyList();
-         return empty.iterator();
-      }
-   }
+
+    @Override
+    public Iterator<ByteBuffer> iterator() {
+        return getBlockIterator();
+    }
+
+    Iterator<ByteBuffer> getBlockIterator() {
+       return (getSize() > 0 ? _stream : Collections.<ByteBuffer>emptyList()).iterator();
+    }
 
    /**
     * @return size of the document
@@ -240,7 +237,7 @@ public final class NPOIFSDocument implem
     *		 store
     */
    public Iterator<Object> getViewableIterator() {
-      return Collections.emptyList().iterator();
+      return emptyList().iterator();
    }
 
    /**
@@ -261,10 +258,7 @@ public final class NPOIFSDocument implem
     * @return short description
     */
    public String getShortDescription() {
-      StringBuffer buffer = new StringBuffer();
 
-      buffer.append("Document: \"").append(_property.getName()).append("\"");
-      buffer.append(" size = ").append(getSize());
-      return buffer.toString();
+       return "Document: \"" + _property.getName() + "\" size = " + getSize();
    }
 }

Modified: poi/trunk/src/java/org/apache/poi/poifs/filesystem/POIFSFileSystem.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/poifs/filesystem/POIFSFileSystem.java?rev=1839201&r1=1839200&r2=1839201&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/poifs/filesystem/POIFSFileSystem.java (original)
+++ poi/trunk/src/java/org/apache/poi/poifs/filesystem/POIFSFileSystem.java Sun Aug 26 11:55:00 2018
@@ -141,6 +141,6 @@ public class POIFSFileSystem
      *             arg[ 1 ] is the output file
      */
     public static void main(String args[]) throws IOException {
-        OPOIFSFileSystem.main(args);
+        NPOIFSFileSystem.main(args);
     }
 }

Copied: poi/trunk/src/java/org/apache/poi/poifs/filesystem/package-info.java (from r1839200, poi/trunk/src/java/org/apache/poi/poifs/filesystem/package.html)
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/poifs/filesystem/package-info.java?p2=poi/trunk/src/java/org/apache/poi/poifs/filesystem/package-info.java&p1=poi/trunk/src/java/org/apache/poi/poifs/filesystem/package.html&r1=1839200&r2=1839201&rev=1839201&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/poifs/filesystem/package.html (original)
+++ poi/trunk/src/java/org/apache/poi/poifs/filesystem/package-info.java Sun Aug 26 11:55:00 2018
@@ -1,6 +1,4 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
-<!--
-   ====================================================================
+/* ====================================================================
    Licensed to the Apache Software Foundation (ASF) under one or more
    contributor license agreements.  See the NOTICE file distributed with
    this work for additional information regarding copyright ownership.
@@ -15,23 +13,11 @@
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
-   ====================================================================
--->
-<html>
-<head>
-</head>
-<body bgcolor="white">
+==================================================================== */
 
-filesystem package maps OLE 2 Compound document files to a more familiar filesystem interface.
-
-<h2>Related Documentation</h2>
-
-For overviews, tutorials, examples, guides, and tool documentation, please see:
-<ul>
-<li><a href="http://poi.apache.org">Apache POI Project</a>
-</ul>
-
-<!-- Put @see and @since tags down here. -->
-@see org.apache.poi.poifs.eventfilesystem
-</body>
-</html>
+/**
+ * filesystem package maps OLE 2 Compound document files to a more familiar filesystem interface.
+ *
+ * @see org.apache.poi.poifs.eventfilesystem
+ */
+package org.apache.poi.poifs.filesystem;
\ No newline at end of file

Copied: poi/trunk/src/java/org/apache/poi/poifs/package-info.java (from r1839200, poi/trunk/src/java/org/apache/poi/poifs/package.html)
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/poifs/package-info.java?p2=poi/trunk/src/java/org/apache/poi/poifs/package-info.java&p1=poi/trunk/src/java/org/apache/poi/poifs/package.html&r1=1839200&r2=1839201&rev=1839201&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/poifs/package.html (original)
+++ poi/trunk/src/java/org/apache/poi/poifs/package-info.java Sun Aug 26 11:55:00 2018
@@ -1,6 +1,4 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
-<!--
-   ====================================================================
+/* ====================================================================
    Licensed to the Apache Software Foundation (ASF) under one or more
    contributor license agreements.  See the NOTICE file distributed with
    this work for additional information regarding copyright ownership.
@@ -15,25 +13,13 @@
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
-   ====================================================================
--->
-<html>
-<head>
-</head>
-<body bgcolor="white">
+==================================================================== */
 
-Poor Obfuscation Implementation FileSystem APIs implement the OLE 2 Compound Document format in
-pure Java.  All POI subprojects are based upon this API.
-
-<h2>Related Documentation</h2>
-
-For overviews, tutorials, examples, guides, and tool documentation, please see:
-<ul>
-<li><a href="http://poi.apache.org">Apache POI Project</a>
-</ul>
-
-<!-- Put @see and @since tags down here. -->
-@see org.apache.poi.hssf
-@see org.apache.poi.hpsf
-</body>
-</html>
+/**
+ * Poor Obfuscation Implementation FileSystem APIs implement the OLE 2 Compound Document format in
+ * pure Java. All POI subprojects are based upon this API.
+ *
+ * @see org.apache.poi.hssf
+ * @see org.apache.poi.hpsf
+ */
+package org.apache.poi.poifs;
\ No newline at end of file

Modified: poi/trunk/src/java/org/apache/poi/poifs/property/DirectoryProperty.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/poifs/property/DirectoryProperty.java?rev=1839201&r1=1839200&r2=1839201&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/poifs/property/DirectoryProperty.java (original)
+++ poi/trunk/src/java/org/apache/poi/poifs/property/DirectoryProperty.java Sun Aug 26 11:55:00 2018
@@ -30,7 +30,7 @@ import java.util.Set;
 /**
  * Directory property
  */
-public class DirectoryProperty extends Property implements Parent, Iterable<Property> { // TODO - fix instantiable superclass
+public class DirectoryProperty extends Property implements Parent, Iterable<Property> {
 
     /** List of Property instances */
     private List<Property> _children;

Modified: poi/trunk/src/java/org/apache/poi/poifs/property/DocumentProperty.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/poifs/property/DocumentProperty.java?rev=1839201&r1=1839200&r2=1839201&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/poifs/property/DocumentProperty.java (original)
+++ poi/trunk/src/java/org/apache/poi/poifs/property/DocumentProperty.java Sun Aug 26 11:55:00 2018
@@ -19,14 +19,14 @@
 
 package org.apache.poi.poifs.property;
 
-import org.apache.poi.poifs.filesystem.OPOIFSDocument;
+import org.apache.poi.poifs.filesystem.NPOIFSDocument;
 
 /**
  * Trivial extension of Property for POIFSDocuments
  */
 public class DocumentProperty extends Property {
     // the POIFSDocument this property is associated with
-    private OPOIFSDocument _document;
+    private NPOIFSDocument _document;
 
     /**
      * Constructor
@@ -64,7 +64,7 @@ public class DocumentProperty extends Pr
      *
      * @param doc the associated POIFSDocument
      */
-    public void setDocument(OPOIFSDocument doc)
+    public void setDocument(NPOIFSDocument doc)
     {
         _document = doc;
     }
@@ -74,7 +74,7 @@ public class DocumentProperty extends Pr
      *
      * @return the associated document
      */
-    public OPOIFSDocument getDocument()
+    public NPOIFSDocument getDocument()
     {
         return _document;
     }

Modified: poi/trunk/src/java/org/apache/poi/poifs/property/RootProperty.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/poifs/property/RootProperty.java?rev=1839201&r1=1839200&r2=1839201&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/poifs/property/RootProperty.java (original)
+++ poi/trunk/src/java/org/apache/poi/poifs/property/RootProperty.java Sun Aug 26 11:55:00 2018
@@ -18,7 +18,6 @@
 package org.apache.poi.poifs.property;
 
 import org.apache.poi.poifs.common.POIFSConstants;
-import org.apache.poi.poifs.storage.SmallDocumentBlock;
 
 /**
  * Root property
@@ -43,9 +42,7 @@ public final class RootProperty extends
      * @param array byte data
      * @param offset offset into byte data
      */
-    protected RootProperty(final int index, final byte [] array,
-                           final int offset)
-    {
+    RootProperty(final int index, final byte [] array, final int offset) {
         super(index, array, offset);
     }
 
@@ -56,7 +53,9 @@ public final class RootProperty extends
      */
     public void setSize(int size)
     {
-        super.setSize(SmallDocumentBlock.calcSize(size));
+        final int BLOCK_SHIFT = 6;
+        final int _block_size = 1 << BLOCK_SHIFT;
+        super.setSize(size * _block_size);
     }
 
     /**

Copied: poi/trunk/src/java/org/apache/poi/poifs/property/package-info.java (from r1839200, poi/trunk/src/java/org/apache/poi/poifs/property/package.html)
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/poifs/property/package-info.java?p2=poi/trunk/src/java/org/apache/poi/poifs/property/package-info.java&p1=poi/trunk/src/java/org/apache/poi/poifs/property/package.html&r1=1839200&r2=1839201&rev=1839201&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/poifs/property/package.html (original)
+++ poi/trunk/src/java/org/apache/poi/poifs/property/package-info.java Sun Aug 26 11:55:00 2018
@@ -1,6 +1,4 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
-<!--
-   ====================================================================
+/* ====================================================================
    Licensed to the Apache Software Foundation (ASF) under one or more
    contributor license agreements.  See the NOTICE file distributed with
    this work for additional information regarding copyright ownership.
@@ -15,23 +13,11 @@
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
-   ====================================================================
--->
-<html>
-<head>
-</head>
-<body bgcolor="white">
+==================================================================== */
 
-property package contains high and low level Property structures for POIFS.
-
-<h2>Related Documentation</h2>
-
-For overviews, tutorials, examples, guides, and tool documentation, please see:
-<ul>
-<li><a href="http://poi.apache.org">Apache POI Project</a>
-</ul>
-
-<!-- Put @see and @since tags down here. -->
-@see org.apache.poi.poifs.filesystem
-</body>
-</html>
+/**
+ * property package contains high and low level Property structures for POIFS.
+ *
+ * @see org.apache.poi.poifs.filesystem
+ */
+package org.apache.poi.poifs.property;
\ No newline at end of file

Modified: poi/trunk/src/java/org/apache/poi/poifs/storage/HeaderBlockConstants.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/poifs/storage/HeaderBlockConstants.java?rev=1839201&r1=1839200&r2=1839201&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/poifs/storage/HeaderBlockConstants.java (original)
+++ poi/trunk/src/java/org/apache/poi/poifs/storage/HeaderBlockConstants.java Sun Aug 26 11:55:00 2018
@@ -27,9 +27,9 @@ import org.apache.poi.util.LittleEndianC
  */
 public interface HeaderBlockConstants
 {
-    public static final long _signature               = 0xE11AB1A1E011CFD0L;
-    public static final int  _bat_array_offset        = 0x4c;
-    public static final int  _max_bats_in_header      =
+    long _signature               = 0xE11AB1A1E011CFD0L;
+    int  _bat_array_offset        = 0x4c;
+    int  _max_bats_in_header      =
         (POIFSConstants.SMALLER_BIG_BLOCK_SIZE - _bat_array_offset)
         / LittleEndianConsts.INT_SIZE; // If 4k blocks, rest is blank
 
@@ -39,12 +39,12 @@ public interface HeaderBlockConstants
     //  XBAT ~= DIFat
     
     // useful offsets
-    public static final int  _signature_offset        = 0;
-    public static final int  _bat_count_offset        = 0x2C;
-    public static final int  _property_start_offset   = 0x30;
-    public static final int  _sbat_start_offset       = 0x3C;
-    public static final int  _sbat_block_count_offset = 0x40;
-    public static final int  _xbat_start_offset       = 0x44;
-    public static final int  _xbat_count_offset       = 0x48;
-}   // end public interface HeaderBlockConstants
+    int  _signature_offset        = 0;
+    int  _bat_count_offset        = 0x2C;
+    int  _property_start_offset   = 0x30;
+    int  _sbat_start_offset       = 0x3C;
+    int  _sbat_block_count_offset = 0x40;
+    int  _xbat_start_offset       = 0x44;
+    int  _xbat_count_offset       = 0x48;
+}
 

Copied: poi/trunk/src/java/org/apache/poi/poifs/storage/package-info.java (from r1839200, poi/trunk/src/java/org/apache/poi/poifs/storage/package.html)
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/poifs/storage/package-info.java?p2=poi/trunk/src/java/org/apache/poi/poifs/storage/package-info.java&p1=poi/trunk/src/java/org/apache/poi/poifs/storage/package.html&r1=1839200&r2=1839201&rev=1839201&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/poifs/storage/package.html (original)
+++ poi/trunk/src/java/org/apache/poi/poifs/storage/package-info.java Sun Aug 26 11:55:00 2018
@@ -1,6 +1,4 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
-<!--
-   ====================================================================
+/* ====================================================================
    Licensed to the Apache Software Foundation (ASF) under one or more
    contributor license agreements.  See the NOTICE file distributed with
    this work for additional information regarding copyright ownership.
@@ -15,22 +13,10 @@
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
-   ====================================================================
--->
-<html>
-<head>
-</head>
-<body bgcolor="white">
+==================================================================== */
 
-storage package contains low level binary structures for POIFS's implementation of the OLE 2
-Compound Document Format.
-
-<h2>Related Documentation</h2>
-
-For overviews, tutorials, examples, guides, and tool documentation, please see:
-<ul>
-<li><a href="http://poi.apache.org">Apache POI Project</a>
-</ul>
-
-</body>
-</html>
+/**
+ * storage package contains low level binary structures for POIFS's implementation of the OLE 2
+ * Compound Document Format.
+ */
+package org.apache.poi.poifs.storage;
\ No newline at end of file

Modified: poi/trunk/src/java/org/apache/poi/util/LittleEndianOutputStream.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/util/LittleEndianOutputStream.java?rev=1839201&r1=1839200&r2=1839201&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/util/LittleEndianOutputStream.java (original)
+++ poi/trunk/src/java/org/apache/poi/util/LittleEndianOutputStream.java Sun Aug 26 11:55:00 2018
@@ -21,10 +21,6 @@ import java.io.FilterOutputStream;
 import java.io.IOException;
 import java.io.OutputStream;
 
-/**
- *
- * @author Josh Micich
- */
 public final class LittleEndianOutputStream extends FilterOutputStream implements LittleEndianOutput {
 	public LittleEndianOutputStream(OutputStream out) {
 		super(out);
@@ -49,7 +45,7 @@ public final class LittleEndianOutputStr
 		int b3 = (v >>> 24) & 0xFF;
 		int b2 = (v >>> 16) & 0xFF;
 		int b1 = (v >>>  8) & 0xFF;
-		int b0 = (v/* >>>  0*/) & 0xFF;
+		int b0 = (v) & 0xFF;
 		try {
 			out.write(b0);
 			out.write(b1);
@@ -69,7 +65,7 @@ public final class LittleEndianOutputStr
 	@Override
     public void writeShort(int v) {
 		int b1 = (v >>>  8) & 0xFF;
-		int b0 = (v/* >>>  0*/) & 0xFF;
+		int b0 = (v) & 0xFF;
 		try {
 			out.write(b0);
 			out.write(b1);
@@ -94,5 +90,38 @@ public final class LittleEndianOutputStr
 		} catch (IOException e) {
 			throw new RuntimeException(e);
 		}
+	}
+
+
+	/**
+	 * Put unsigned int into output stream
+	 *
+	 * @param value
+	 *            the int (32-bit) value
+	 */
+	public void writeUInt( long value ) {
+		try {
+			out.write( (byte) ( ( value ) & 0xFF ) );
+			out.write( (byte) ( ( value >>> 8 ) & 0xFF ) );
+			out.write( (byte) ( ( value >>> 16 ) & 0xFF ) );
+			out.write( (byte) ( ( value >>> 24 ) & 0xFF ) );
+		} catch (IOException e) {
+			throw new RuntimeException(e);
+		}
+	}
+
+	/**
+	 * Put unsigned short into output stream
+	 *
+	 * @param value
+	 *            the unsigned short (16-bit) value
+	 */
+	public void putUShort( int value ) {
+		try {
+			out.write( (byte) ( ( value ) & 0xFF ) );
+			out.write( (byte) ( ( value >>> 8 ) & 0xFF ) );
+		} catch (IOException e) {
+			throw new RuntimeException(e);
+		}
 	}
 }

Modified: poi/trunk/src/ooxml/java/org/apache/poi/ooxml/extractor/ExtractorFactory.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/ooxml/extractor/ExtractorFactory.java?rev=1839201&r1=1839200&r2=1839201&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/ooxml/extractor/ExtractorFactory.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/ooxml/extractor/ExtractorFactory.java Sun Aug 26 11:55:00 2018
@@ -48,7 +48,6 @@ import org.apache.poi.poifs.filesystem.E
 import org.apache.poi.poifs.filesystem.FileMagic;
 import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
 import org.apache.poi.poifs.filesystem.NotOLE2FileException;
-import org.apache.poi.poifs.filesystem.OPOIFSFileSystem;
 import org.apache.poi.poifs.filesystem.OfficeXmlFileException;
 import org.apache.poi.poifs.filesystem.POIFSFileSystem;
 import org.apache.poi.sl.extractor.SlideShowExtractor;
@@ -79,12 +78,15 @@ import org.apache.xmlbeans.XmlException;
  *  off switching to <a href="http://tika.apache.org">Apache Tika</a> instead!</p>
  */
 @SuppressWarnings("WeakerAccess")
-public class ExtractorFactory {
+public final class ExtractorFactory {
     private static final POILogger logger = POILogFactory.getLogger(ExtractorFactory.class);
     
     public static final String CORE_DOCUMENT_REL = PackageRelationshipTypes.CORE_DOCUMENT;
-    protected static final String VISIO_DOCUMENT_REL = PackageRelationshipTypes.VISIO_CORE_DOCUMENT;
-    protected static final String STRICT_DOCUMENT_REL = PackageRelationshipTypes.STRICT_CORE_DOCUMENT;
+    private static final String VISIO_DOCUMENT_REL = PackageRelationshipTypes.VISIO_CORE_DOCUMENT;
+    private static final String STRICT_DOCUMENT_REL = PackageRelationshipTypes.STRICT_CORE_DOCUMENT;
+
+    private ExtractorFactory() {
+    }
 
     /**
      * Should this thread prefer event based over usermodel based extractors?
@@ -128,6 +130,7 @@ public class ExtractorFactory {
          return OLE2ExtractorFactory.getPreferEventExtractor();
     }
 
+    @SuppressWarnings("unchecked")
     public static <T extends POITextExtractor> T createExtractor(File f) throws IOException, OpenXML4JException, XmlException {
         NPOIFSFileSystem fs = null;
         try {
@@ -230,13 +233,13 @@ public class ExtractorFactory {
             // Is it XSLF?
             for (XSLFRelation rel : XSLFPowerPointExtractor.SUPPORTED_TYPES) {
                 if ( rel.getContentType().equals( contentType ) ) {
-                    return new SlideShowExtractor(new XMLSlideShow(pkg));
+                    return new SlideShowExtractor<>(new XMLSlideShow(pkg));
                 }
             }
      
             // special handling for SlideShow-Theme-files, 
             if (XSLFRelation.THEME_MANAGER.getContentType().equals(contentType)) {
-                return new SlideShowExtractor(new XMLSlideShow(pkg));
+                return new SlideShowExtractor<>(new XMLSlideShow(pkg));
             }
 
             // How about xlsb?
@@ -262,10 +265,8 @@ public class ExtractorFactory {
     public static <T extends POITextExtractor> T createExtractor(NPOIFSFileSystem fs) throws IOException, OpenXML4JException, XmlException {
         return createExtractor(fs.getRoot());
     }
-    public static <T extends POITextExtractor> T createExtractor(OPOIFSFileSystem fs) throws IOException, OpenXML4JException, XmlException {
-        return createExtractor(fs.getRoot());
-    }
 
+    @SuppressWarnings("unchecked")
     public static <T extends POITextExtractor> T createExtractor(DirectoryNode poifsDir) throws IOException, OpenXML4JException, XmlException
     {
         // First, check for OOXML
@@ -374,7 +375,7 @@ public class ExtractorFactory {
                 throw new IOException(e.getMessage(), e);
             }
         }
-        return textExtractors.toArray(new POITextExtractor[textExtractors.size()]);
+        return textExtractors.toArray(new POITextExtractor[0]);
     }
 
     /**

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/extractor/ooxml/TestExtractorFactory.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/extractor/ooxml/TestExtractorFactory.java?rev=1839201&r1=1839200&r2=1839201&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/extractor/ooxml/TestExtractorFactory.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/extractor/ooxml/TestExtractorFactory.java Sun Aug 26 11:55:00 2018
@@ -30,10 +30,9 @@ import java.io.IOException;
 import java.util.Locale;
 
 import org.apache.poi.POIDataSamples;
+import org.apache.poi.UnsupportedFileFormatException;
 import org.apache.poi.extractor.POIOLE2TextExtractor;
 import org.apache.poi.extractor.POITextExtractor;
-import org.apache.poi.ooxml.extractor.POIXMLTextExtractor;
-import org.apache.poi.UnsupportedFileFormatException;
 import org.apache.poi.hdgf.extractor.VisioTextExtractor;
 import org.apache.poi.hpbf.extractor.PublisherTextExtractor;
 import org.apache.poi.hsmf.extractor.OutlookTextExtactor;
@@ -44,14 +43,12 @@ import org.apache.poi.hssf.extractor.Exc
 import org.apache.poi.hwpf.extractor.Word6Extractor;
 import org.apache.poi.hwpf.extractor.WordExtractor;
 import org.apache.poi.ooxml.extractor.ExtractorFactory;
+import org.apache.poi.ooxml.extractor.POIXMLTextExtractor;
 import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
 import org.apache.poi.openxml4j.opc.OPCPackage;
 import org.apache.poi.openxml4j.opc.PackageAccess;
-import org.apache.poi.poifs.filesystem.OPOIFSFileSystem;
 import org.apache.poi.poifs.filesystem.POIFSFileSystem;
 import org.apache.poi.sl.extractor.SlideShowExtractor;
-import org.apache.poi.util.POILogFactory;
-import org.apache.poi.util.POILogger;
 import org.apache.poi.xdgf.extractor.XDGFVisioExtractor;
 import org.apache.poi.xssf.extractor.XSSFBEventBasedExcelExtractor;
 import org.apache.poi.xssf.extractor.XSSFEventBasedExcelExtractor;
@@ -65,11 +62,10 @@ import org.junit.Test;
  */
 public class TestExtractorFactory {
 
-    private static final POILogger LOG = POILogFactory.getLogger(TestExtractorFactory.class);
-
     private static final POIDataSamples ssTests = POIDataSamples.getSpreadSheetInstance();
     private static final File xls = getFileAndCheck(ssTests, "SampleSS.xls");
     private static final File xlsx = getFileAndCheck(ssTests, "SampleSS.xlsx");
+    @SuppressWarnings("unused")
     private static final File xlsxStrict = getFileAndCheck(ssTests, "SampleSS.strict.xlsx");
     private static final File xltx = getFileAndCheck(ssTests, "test.xltx");
     private static final File xlsEmb = getFileAndCheck(ssTests, "excel_with_embeded.xls");
@@ -150,17 +146,19 @@ public class TestExtractorFactory {
     @Test(expected = IllegalArgumentException.class)
     public void testFileInvalid() throws Exception {
         // Text
-        try (POITextExtractor te = ExtractorFactory.createExtractor(txt)) {}
+        try (POITextExtractor ignored = ExtractorFactory.createExtractor(txt)) {
+            fail("extracting from invalid package");
+        }
     }
 
     @Test
     public void testInputStream() throws Exception {
-        testStream((f) -> ExtractorFactory.createExtractor(f), true);
+        testStream(ExtractorFactory::createExtractor, true);
     }
 
     @Test(expected = IllegalArgumentException.class)
     public void testInputStreamInvalid() throws Exception {
-        testInvalid((f) -> ExtractorFactory.createExtractor(f));
+        testInvalid(ExtractorFactory::createExtractor);
     }
 
     @Test
@@ -173,17 +171,6 @@ public class TestExtractorFactory {
         testInvalid((f) -> ExtractorFactory.createExtractor(new POIFSFileSystem(f)));
     }
 
-    @Test
-    public void testOPOIFS() throws Exception {
-        testStream((f) -> ExtractorFactory.createExtractor(new OPOIFSFileSystem(f)), false);
-    }
-
-    @Test(expected = IOException.class)
-    public void testOPOIFSInvalid() throws Exception {
-        testInvalid((f) -> ExtractorFactory.createExtractor(new OPOIFSFileSystem(f)));
-    }
-
-
     private void testStream(final FunctionEx<FileInputStream, POITextExtractor> poifsIS, final boolean loadOOXML)
     throws IOException, OpenXML4JException, XmlException {
         for (int i = 0; i < TEST_SET.length; i += 4) {
@@ -213,7 +200,8 @@ public class TestExtractorFactory {
     private void testInvalid(FunctionEx<FileInputStream, POITextExtractor> poifs) throws IOException, OpenXML4JException, XmlException {
         // Text
         try (FileInputStream fis = new FileInputStream(txt);
-             POITextExtractor te = poifs.apply(fis)) {
+             POITextExtractor ignored = poifs.apply(fis)) {
+            fail("extracting from invalid package");
         }
     }
 
@@ -237,7 +225,9 @@ public class TestExtractorFactory {
     public void testPackageInvalid() throws Exception {
         // Text
         try (final OPCPackage pkg = OPCPackage.open(txt, PackageAccess.READ);
-             final POITextExtractor te = ExtractorFactory.createExtractor(pkg)) {}
+             final POITextExtractor ignored = ExtractorFactory.createExtractor(pkg)) {
+            fail("extracting from invalid package");
+        }
     }
 
     @Test
@@ -452,7 +442,7 @@ public class TestExtractorFactory {
     };
     
     @Test
-    public void testFileLeak() throws Exception {
+    public void testFileLeak() {
         // run a number of files that might fail in order to catch 
         // leaked file resources when using file-leak-detector while
         // running the test

Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/extractor/TestExtractor.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/extractor/TestExtractor.java?rev=1839201&r1=1839200&r2=1839201&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/extractor/TestExtractor.java (original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/extractor/TestExtractor.java Sun Aug 26 11:55:00 2018
@@ -27,7 +27,6 @@ import static org.junit.Assert.assertTru
 
 import java.io.ByteArrayOutputStream;
 import java.io.File;
-import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.List;
@@ -35,12 +34,10 @@ import java.util.List;
 import org.apache.poi.POIDataSamples;
 import org.apache.poi.hslf.usermodel.HSLFObjectShape;
 import org.apache.poi.hslf.usermodel.HSLFSlideShow;
-import org.apache.poi.hslf.usermodel.HSLFSlideShowImpl;
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.apache.poi.hwpf.HWPFDocument;
 import org.apache.poi.poifs.filesystem.DirectoryNode;
 import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
-import org.apache.poi.poifs.filesystem.OPOIFSFileSystem;
 import org.apache.poi.poifs.filesystem.POIFSFileSystem;
 import org.apache.poi.sl.extractor.SlideShowExtractor;
 import org.apache.poi.sl.usermodel.ObjectShape;
@@ -68,18 +65,7 @@ public final class TestExtractor {
      */
     private static POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
 
-//    @Before
-//    public void setUp() throws Exception {
-//        ppe = new PowerPointExtractor(slTests.getFile("basic_test_ppt_file.ppt").getCanonicalPath());
-//        ppe2 = new PowerPointExtractor(slTests.getFile("with_textbox.ppt").getCanonicalPath());
-//    }
-
-//    @After
-//    public void closeResources() throws Exception {
-//        ppe2.close();
-//        ppe.close();
-//    }
-
+    @SuppressWarnings("unchecked")
     private SlideShowExtractor<?,?> openExtractor(String fileName) throws IOException {
         try (InputStream is = slTests.openResourceAsStream(fileName)) {
             return new SlideShowExtractor(SlideShowFactory.create(is));
@@ -151,8 +137,6 @@ public final class TestExtractor {
     /**
      * Test that when presented with a PPT file missing the odd
      * core record, we can still get the rest of the text out
-     *
-     * @throws Exception
      */
     @Test
     public void testMissingCoreRecords() throws IOException {
@@ -191,7 +175,7 @@ public final class TestExtractor {
                 assertTrue(dir.hasEntry(HSLFSlideShow.POWERPOINT_DOCUMENT));
 
                 try (final SlideShow<?,?> ppt = SlideShowFactory.create(dir);
-                     final SlideShowExtractor<?,?> ppe = new SlideShowExtractor(ppt)) {
+                     final SlideShowExtractor<?,?> ppe = new SlideShowExtractor<>(ppt)) {
                     assertEquals(TEST_SET[i+1], ppe.getText());
                 }
             }
@@ -297,7 +281,7 @@ public final class TestExtractor {
     }
 
     private void testHeaderFooterInner(final HSLFSlideShow ppt) throws IOException {
-        try (final SlideShowExtractor<?,?> ppe = new SlideShowExtractor(ppt)) {
+        try (final SlideShowExtractor<?,?> ppe = new SlideShowExtractor<>(ppt)) {
             String text = ppe.getText();
             assertFalse("Header shouldn't be there by default\n" + text, text.contains("testdoc"));
             assertFalse("Header shouldn't be there by default\n" + text, text.contains("test phrase"));
@@ -399,19 +383,11 @@ public final class TestExtractor {
     public void testDifferentPOIFS() throws IOException {
         // Open the two filesystems
         File pptFile = slTests.getFile("basic_test_ppt_file.ppt");
-        try (final InputStream is1 = new FileInputStream(pptFile);
-            final NPOIFSFileSystem npoifs = new NPOIFSFileSystem(pptFile)) {
-
-            final OPOIFSFileSystem opoifs = new OPOIFSFileSystem(is1);
-
-            DirectoryNode[] files = {opoifs.getRoot(), npoifs.getRoot()};
-
+        try (final NPOIFSFileSystem npoifs = new NPOIFSFileSystem(pptFile, true)) {
             // Open directly
-            for (DirectoryNode dir : files) {
-                try (SlideShow<?,?> ppt = SlideShowFactory.create(dir);
-                    SlideShowExtractor<?,?> extractor = new SlideShowExtractor(ppt)) {
-                    assertEquals(expectText, extractor.getText());
-                }
+            try (SlideShow<?,?> ppt = SlideShowFactory.create(npoifs.getRoot());
+                SlideShowExtractor<?,?> extractor = new SlideShowExtractor<>(ppt)) {
+                assertEquals(expectText, extractor.getText());
             }
         }
     }



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org