]> source.dussan.org Git - poi.git/commitdiff
Allow Ole10Native to be created from a DirectoryNode, not only a a POIFS
authorNick Burch <nick@apache.org>
Sat, 15 Oct 2011 10:27:52 +0000 (10:27 +0000)
committerNick Burch <nick@apache.org>
Sat, 15 Oct 2011 10:27:52 +0000 (10:27 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1183618 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/poi/poifs/filesystem/Ole10Native.java

index 488bfb3053867678cf57a717d4ae2a106c38dbea..db05d97d9f46fe6bd78a57d1d3b3b962ba950ba3 100644 (file)
 \r
 package org.apache.poi.poifs.filesystem;\r
 \r
-import org.apache.poi.util.*;\r
-\r
-import java.io.ByteArrayOutputStream;\r
 import java.io.FileNotFoundException;\r
 import java.io.IOException;\r
-import java.util.Arrays;\r
+\r
+import org.apache.poi.util.HexDump;\r
+import org.apache.poi.util.LittleEndian;\r
+import org.apache.poi.util.LittleEndianConsts;\r
+import org.apache.poi.util.StringUtil;\r
 \r
 /**\r
  * Represents an Ole10Native record which is wrapped around certain binary\r
@@ -57,23 +58,37 @@ public class Ole10Native {
    * @throws Ole10NativeException on invalid or unexcepted data format\r
    */\r
   public static Ole10Native createFromEmbeddedOleObject(POIFSFileSystem poifs) throws IOException, Ole10NativeException {\r
-    boolean plain = false;\r
-\r
-    try {\r
-      poifs.getRoot().getEntry("\u0001Ole10ItemName");\r
-      plain = true;\r
-    } catch (FileNotFoundException ex) {\r
-      plain = false;\r
-    }\r
+     return createFromEmbeddedOleObject(poifs.getRoot());\r
+  }\r
+  \r
+  /**\r
+   * Creates an instance of this class from an embedded OLE Object. The OLE Object is expected\r
+   * to include a stream &quot;{01}Ole10Native&quot; which contains the actual\r
+   * data relevant for this class.\r
+   *\r
+   * @param poifs POI Filesystem object\r
+   * @return Returns an instance of this class\r
+   * @throws IOException on IO error\r
+   * @throws Ole10NativeException on invalid or unexcepted data format\r
+   */\r
+  public static Ole10Native createFromEmbeddedOleObject(DirectoryNode directory) throws IOException, Ole10NativeException {\r
+     boolean plain = false;\r
 \r
-    DocumentInputStream dis = poifs.createDocumentInputStream(OLE10_NATIVE);\r
-    ByteArrayOutputStream bos = new ByteArrayOutputStream();\r
-    IOUtils.copy(dis, bos);\r
-    byte[] data = bos.toByteArray();\r
+     try {\r
+        directory.getEntry("\u0001Ole10ItemName");\r
+        plain = true;\r
+     } catch (FileNotFoundException ex) {\r
+        plain = false;\r
+     }\r
+     \r
+     DocumentEntry nativeEntry = \r
+        (DocumentEntry)directory.getEntry(OLE10_NATIVE);\r
+     byte[] data = new byte[nativeEntry.getSize()];\r
+     directory.createDocumentInputStream(nativeEntry).read(data);\r
 \r
-    return new Ole10Native(data, 0, plain);\r
+     return new Ole10Native(data, 0, plain);\r
   }\r
-\r
+  \r
   /**\r
    * Creates an instance and fills the fields based on the data in the given buffer.\r
    *\r