\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
* @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 "{01}Ole10Native" 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