mirror of https://github.com/apache/poi.git
Allow Ole10Native to be created from a DirectoryNode, not only a a POIFS
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1183618 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
e483b6c41d
commit
ee76e11d17
|
@ -17,12 +17,13 @@
|
||||||
|
|
||||||
package org.apache.poi.poifs.filesystem;
|
package org.apache.poi.poifs.filesystem;
|
||||||
|
|
||||||
import org.apache.poi.util.*;
|
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Arrays;
|
|
||||||
|
import org.apache.poi.util.HexDump;
|
||||||
|
import org.apache.poi.util.LittleEndian;
|
||||||
|
import org.apache.poi.util.LittleEndianConsts;
|
||||||
|
import org.apache.poi.util.StringUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents an Ole10Native record which is wrapped around certain binary
|
* Represents an Ole10Native record which is wrapped around certain binary
|
||||||
|
@ -57,23 +58,37 @@ public class Ole10Native {
|
||||||
* @throws Ole10NativeException on invalid or unexcepted data format
|
* @throws Ole10NativeException on invalid or unexcepted data format
|
||||||
*/
|
*/
|
||||||
public static Ole10Native createFromEmbeddedOleObject(POIFSFileSystem poifs) throws IOException, Ole10NativeException {
|
public static Ole10Native createFromEmbeddedOleObject(POIFSFileSystem poifs) throws IOException, Ole10NativeException {
|
||||||
boolean plain = false;
|
return createFromEmbeddedOleObject(poifs.getRoot());
|
||||||
|
|
||||||
try {
|
|
||||||
poifs.getRoot().getEntry("\u0001Ole10ItemName");
|
|
||||||
plain = true;
|
|
||||||
} catch (FileNotFoundException ex) {
|
|
||||||
plain = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
DocumentInputStream dis = poifs.createDocumentInputStream(OLE10_NATIVE);
|
|
||||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
|
||||||
IOUtils.copy(dis, bos);
|
|
||||||
byte[] data = bos.toByteArray();
|
|
||||||
|
|
||||||
return new Ole10Native(data, 0, plain);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates an instance of this class from an embedded OLE Object. The OLE Object is expected
|
||||||
|
* to include a stream "{01}Ole10Native" which contains the actual
|
||||||
|
* data relevant for this class.
|
||||||
|
*
|
||||||
|
* @param poifs POI Filesystem object
|
||||||
|
* @return Returns an instance of this class
|
||||||
|
* @throws IOException on IO error
|
||||||
|
* @throws Ole10NativeException on invalid or unexcepted data format
|
||||||
|
*/
|
||||||
|
public static Ole10Native createFromEmbeddedOleObject(DirectoryNode directory) throws IOException, Ole10NativeException {
|
||||||
|
boolean plain = false;
|
||||||
|
|
||||||
|
try {
|
||||||
|
directory.getEntry("\u0001Ole10ItemName");
|
||||||
|
plain = true;
|
||||||
|
} catch (FileNotFoundException ex) {
|
||||||
|
plain = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
DocumentEntry nativeEntry =
|
||||||
|
(DocumentEntry)directory.getEntry(OLE10_NATIVE);
|
||||||
|
byte[] data = new byte[nativeEntry.getSize()];
|
||||||
|
directory.createDocumentInputStream(nativeEntry).read(data);
|
||||||
|
|
||||||
|
return new Ole10Native(data, 0, plain);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an instance and fills the fields based on the data in the given buffer.
|
* Creates an instance and fills the fields based on the data in the given buffer.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue