You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ni...@apache.org on 2010/12/29 04:30:08 UTC
svn commit: r1053522 - in /poi/trunk/src/java/org/apache/poi:
POIDocument.java poifs/filesystem/DirectoryNode.java
Author: nick
Date: Wed Dec 29 03:30:07 2010
New Revision: 1053522
URL: http://svn.apache.org/viewvc?rev=1053522&view=rev
Log:
Add a NPOIFS aware createDocumentInputStream method to DirectoryNode, and use it in POIDocument. Also fix indent in the latter
Modified:
poi/trunk/src/java/org/apache/poi/POIDocument.java
poi/trunk/src/java/org/apache/poi/poifs/filesystem/DirectoryNode.java
Modified: poi/trunk/src/java/org/apache/poi/POIDocument.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/POIDocument.java?rev=1053522&r1=1053521&r2=1053522&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/POIDocument.java (original)
+++ poi/trunk/src/java/org/apache/poi/POIDocument.java Wed Dec 29 03:30:07 2010
@@ -20,6 +20,7 @@ package org.apache.poi;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
+import java.io.InputStream;
import java.io.OutputStream;
import java.util.Iterator;
import java.util.List;
@@ -140,31 +141,31 @@ public abstract class POIDocument {
* if it wasn't found
*/
protected PropertySet getPropertySet(String setName) {
- //directory can be null when creating new documents
- if(directory == null) return null;
-
- DocumentInputStream dis;
- try {
- // Find the entry, and get an input stream for it
- dis = directory.createDocumentInputStream(setName);
- } catch(IOException ie) {
- // Oh well, doesn't exist
- logger.log(POILogger.WARN, "Error getting property set with name " + setName + "\n" + ie);
- return null;
- }
+ //directory can be null when creating new documents
+ if(directory == null) return null;
- try {
- // Create the Property Set
- PropertySet set = PropertySetFactory.create(dis);
- return set;
- } catch(IOException ie) {
- // Must be corrupt or something like that
- logger.log(POILogger.WARN, "Error creating property set with name " + setName + "\n" + ie);
- } catch(org.apache.poi.hpsf.HPSFException he) {
- // Oh well, doesn't exist
- logger.log(POILogger.WARN, "Error creating property set with name " + setName + "\n" + he);
- }
- return null;
+ InputStream dis;
+ try {
+ // Find the entry, and get an input stream for it
+ dis = directory.createDocumentInputStream( directory.getEntry(setName) );
+ } catch(IOException ie) {
+ // Oh well, doesn't exist
+ logger.log(POILogger.WARN, "Error getting property set with name " + setName + "\n" + ie);
+ return null;
+ }
+
+ try {
+ // Create the Property Set
+ PropertySet set = PropertySetFactory.create(dis);
+ return set;
+ } catch(IOException ie) {
+ // Must be corrupt or something like that
+ logger.log(POILogger.WARN, "Error creating property set with name " + setName + "\n" + ie);
+ } catch(org.apache.poi.hpsf.HPSFException he) {
+ // Oh well, doesn't exist
+ logger.log(POILogger.WARN, "Error creating property set with name " + setName + "\n" + he);
+ }
+ return null;
}
/**
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=1053522&r1=1053521&r2=1053522&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 Wed Dec 29 03:30:07 2010
@@ -19,9 +19,14 @@
package org.apache.poi.poifs.filesystem;
-import java.io.*;
-
-import java.util.*;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
import org.apache.poi.hpsf.ClassID;
import org.apache.poi.poifs.dev.POIFSViewable;
@@ -162,7 +167,6 @@ public class DirectoryNode
* @exception IOException if the document does not exist or the
* name is that of a DirectoryEntry
*/
-
public DocumentInputStream createDocumentInputStream(
final String documentName)
throws IOException
@@ -178,6 +182,33 @@ public class DirectoryNode
}
/**
+ * open a document in the directory's entry's list of entries
+ *
+ * @param documentEntry the document to be opened
+ *
+ * @return a newly opened DocumentInputStream or NDocumentInputStream
+ *
+ * @exception IOException if the document does not exist or the
+ * name is that of a DirectoryEntry
+ */
+ public InputStream createDocumentInputStream(
+ final Entry document)
+ throws IOException
+ {
+ if (!document.isDocumentEntry()) {
+ throw new IOException("Entry '" + document.getName()
+ + "' is not a DocumentEntry");
+ }
+
+ DocumentEntry entry = (DocumentEntry)document;
+ if(_ofilesystem != null) {
+ return new DocumentInputStream(entry);
+ } else {
+ return new NDocumentInputStream(entry);
+ }
+ }
+
+ /**
* create a new DocumentEntry
*
* @param document the new document
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org