<changes>
<release version="3.7-SNAPSHOT" date="2010-??-??">
+ <action dev="POI-DEVELOPERS" type="add">Avoid creating temporary files when opening OPC packages from input stream</action>
<action dev="POI-DEVELOPERS" type="add">Improved how HSMF handles multiple recipients</action>
<action dev="POI-DEVELOPERS" type="add">Add PublisherTextExtractor support to ExtractorFactory</action>
<action dev="POI-DEVELOPERS" type="add">Add XSLF support for text extraction from tables</action>
*/
public abstract List<PackagePart> getAllEmbedds() throws OpenXML4JException;
- /**
- * YK: current implementation of OpenXML4J is funny.
- * Packages opened by Package.open(InputStream is) are read-only,
- * there is no way to change or even save such an instance in a OutputStream.
- * The workaround is to create a copy via a temp file
- */
- protected static OPCPackage ensureWriteAccess(OPCPackage pkg) throws IOException {
- if(pkg.getPackageAccess() == PackageAccess.READ){
- try {
- return PackageHelper.clone(pkg);
- } catch (OpenXML4JException e){
- throw new POIXMLException(e);
- }
- }
- return pkg;
- }
-
protected final void load(POIXMLFactory factory) throws IOException {
Map<PackagePart, POIXMLDocumentPart> context = new HashMap<PackagePart, POIXMLDocumentPart>();
try {
*/
public static OPCPackage open(InputStream in) throws InvalidFormatException,
IOException {
- OPCPackage pack = new ZipPackage(in, PackageAccess.READ);
+ OPCPackage pack = new ZipPackage(in, PackageAccess.READ_WRITE);
if (pack.partList == null) {
pack.getParts();
}
*/
public final class PackageHelper {
- /**
- * Clone the specified package.
- *
- * @param pkg the package to clone
- * @return the cloned package
- */
- public static OPCPackage clone(OPCPackage pkg) throws OpenXML4JException, IOException {
- return clone(pkg, createTempFile());
- }
-
public static OPCPackage open(InputStream is) throws IOException {
- File file = TempFile.createTempFile("poi-ooxml-", ".tmp");
- FileOutputStream out = new FileOutputStream(file);
- IOUtils.copy(is, out);
- out.close();
try {
- return OPCPackage.open(file.getAbsolutePath());
+ return OPCPackage.open(is);
} catch (InvalidFormatException e){
throw new POIXMLException(e);
}
* @param pkg the OpenXML4J <code>Package</code> object.
*/
public XSSFWorkbook(OPCPackage pkg) throws IOException {
- super(ensureWriteAccess(pkg));
+ super(pkg);
//build a tree of POIXMLDocumentParts, this workbook being the root
load(XSSFFactory.getInstance());
public XSSFWorkbook(InputStream is) throws IOException {
super(PackageHelper.open(is));
-
+
//build a tree of POIXMLDocumentParts, this workbook being the root
load(XSSFFactory.getInstance());
}
private XWPFHeaderFooterPolicy headerFooterPolicy;
public XWPFDocument(OPCPackage pkg) throws IOException {
- super(ensureWriteAccess(pkg));
+ super(pkg);
//build a tree of POIXMLDocumentParts, this document being the root
load(XWPFFactory.getInstance());