incubator-odf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From devin...@apache.org
Subject svn commit: r1204151 - /incubator/odf/trunk/odfdom/src/main/java/org/odftoolkit/odfdom/pkg/OdfPackage.java
Date Sun, 20 Nov 2011 12:04:22 GMT
Author: devinhan
Date: Sun Nov 20 12:04:22 2011
New Revision: 1204151

URL: http://svn.apache.org/viewvc?rev=1204151&view=rev
Log:
#ODFTOOLKIT-104# Create new spreadsheet, save it, load it, add a sheet, save it, then load
it causes failure. [Developer:Devin]

Modified:
    incubator/odf/trunk/odfdom/src/main/java/org/odftoolkit/odfdom/pkg/OdfPackage.java

Modified: incubator/odf/trunk/odfdom/src/main/java/org/odftoolkit/odfdom/pkg/OdfPackage.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/odfdom/src/main/java/org/odftoolkit/odfdom/pkg/OdfPackage.java?rev=1204151&r1=1204150&r2=1204151&view=diff
==============================================================================
--- incubator/odf/trunk/odfdom/src/main/java/org/odftoolkit/odfdom/pkg/OdfPackage.java (original)
+++ incubator/odf/trunk/odfdom/src/main/java/org/odftoolkit/odfdom/pkg/OdfPackage.java Sun
Nov 20 12:04:22 2011
@@ -195,10 +195,36 @@ public class OdfPackage implements Close
 	private OdfPackage(File pkgFile) throws Exception {
 		this();
 		mBaseURI = getBaseURLFromFile(pkgFile);
-		initializeZip(new FileInputStream(pkgFile));
+		InputStream packageStream = new FileInputStream(pkgFile);
+		initializeZip(packageStream);
+		packageStream.close();
 	}
 
 	/**
+	 * Creates an OdfPackage from the OpenDocument provided by a File.
+	 *
+	 * <p>
+	 * OdfPackage relies on the file being available for read access over the
+	 * whole lifecycle of OdfPackage.
+	 * </p>
+	 *
+	 * @param pkgFile a file representing the ODF document
+	 * @param baseURI defining the base URI of ODF package.
+	 * @param errorHandler - SAX ErrorHandler used for ODF validation
+	 * @throws java.lang.Exception - if the package could not be created
+	 * 
+	 * @see #getErrorHandler*
+	 */
+	private OdfPackage(File pkgFile, String baseURI, ErrorHandler errorHandler) throws Exception
{
+		this();
+		mErrorHandler = errorHandler;
+		mBaseURI = baseURI;
+		InputStream packageStream = new FileInputStream(pkgFile);
+		initializeZip(packageStream);
+		packageStream.close();
+	}
+	
+	/**
 	 * Creates an OdfPackage from the OpenDocument provided by a InputStream.
 	 *
 	 * <p>Since an InputStream does not provide the arbitrary (non sequentiell)
@@ -208,8 +234,8 @@ public class OdfPackage implements Close
 	 * @param packageStream - an inputStream representing the ODF package
 	 * @param baseURI defining the base URI of ODF package.
 	 * @param errorHandler - SAX ErrorHandler used for ODF validation
-	 * @see #getErrorHandler
 	 * @throws java.lang.Exception - if the package could not be created
+	 * 
 	 * @see #getErrorHandler*
 	 */
 	private OdfPackage(InputStream packageStream, String baseURI, ErrorHandler errorHandler)
throws Exception {
@@ -235,7 +261,7 @@ public class OdfPackage implements Close
 	 */
 	public static OdfPackage loadPackage(String path) throws Exception {
 		File pkgFile = new File(path);
-		return new OdfPackage(new FileInputStream(pkgFile), getBaseURLFromFile(pkgFile), null);
+		return new OdfPackage(pkgFile, getBaseURLFromFile(pkgFile), null);
 	}
 
 	/**
@@ -251,7 +277,7 @@ public class OdfPackage implements Close
 	 * @throws java.lang.Exception - if the package could not be loaded
 	 */
 	public static OdfPackage loadPackage(File pkgFile) throws Exception {
-		return new OdfPackage(new FileInputStream(pkgFile), getBaseURLFromFile(pkgFile), null);
+		return new OdfPackage(pkgFile, getBaseURLFromFile(pkgFile), null);
 	}
 
 	/**
@@ -303,7 +329,7 @@ public class OdfPackage implements Close
 	 * @see #getErrorHandler
 	 */
 	public static OdfPackage loadPackage(File pkgFile, ErrorHandler errorHandler) throws Exception
{
-		return new OdfPackage(new FileInputStream(pkgFile), getBaseURLFromFile(pkgFile), errorHandler);
+		return new OdfPackage(pkgFile, getBaseURLFromFile(pkgFile), errorHandler);
 	}
 
 	// Initialize using memory



Mime
View raw message