You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-commits@xmlgraphics.apache.org by je...@apache.org on 2008/07/30 08:50:49 UTC

svn commit: r680923 - in /xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/modca/resource: ResourceManager.java ResourceStore.java

Author: jeremias
Date: Tue Jul 29 23:50:49 2008
New Revision: 680923

URL: http://svn.apache.org/viewvc?rev=680923&view=rev
Log:
Bugfix: ResourceStore didn't close the RandomAccessFile and therefore couldn't close the temporary file. Not even deleteOnExit() can help in that case.

Modified:
    xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/modca/resource/ResourceManager.java
    xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/modca/resource/ResourceStore.java

Modified: xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/modca/resource/ResourceManager.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/modca/resource/ResourceManager.java?rev=680923&r1=680922&r2=680923&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/modca/resource/ResourceManager.java (original)
+++ xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/modca/resource/ResourceManager.java Tue Jul 29 23:50:49 2008
@@ -5,9 +5,9 @@
  * The ASF licenses this file to You under the Apache License, Version 2.0
  * (the "License"); you may not use this file except in compliance with
  * the License.  You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -15,7 +15,7 @@
  * limitations under the License.
  */
 
-/* $Id: $ */
+/* $Id$ */
 
 package org.apache.fop.render.afp.modca.resource;
 
@@ -31,7 +31,7 @@
 import org.apache.fop.render.afp.modca.Registry;
 
 /**
- * Manages the creation and storage of document resources 
+ * Manages the creation and storage of document resources
  */
 public class ResourceManager {
     /** Static logging instance */
@@ -39,16 +39,16 @@
 
     /** Resource storage */
     private ResourceStore store;
-    
+
     /** Resource creation factory */
     private ResourceFactory factory;
 
     private ExternalResourceManager external;
-    
+
     /** Mapping of resource info --> store info */
     private Map/*<ResourceInfo,StoreInfo>*/ resourceStorageMap
             = new java.util.HashMap/*<ResourceInfo,StoreInfo>*/();
-    
+
     /**
      * Main constructor
      */
@@ -59,12 +59,12 @@
     }
 
     /**
-     * Creates and adds a new data object and stores the save record to a temporary file.  
-     * 
+     * Creates and adds a new data object and stores the save record to a temporary file.
+     *
      * @param dataObjectInfo a data object info
-     * 
+     *
      * @return a new store save information record
-     * 
+     *
      * @throws java.io.IOException an I/O exception of some sort has occurred.
      */
     public StoreInfo create(DataObjectInfo dataObjectInfo) throws IOException {
@@ -95,7 +95,7 @@
 
     /**
      * Returns the resource factory
-     * 
+     *
      * @return the resource factory
      */
     public ResourceFactory getFactory() {
@@ -104,7 +104,7 @@
 
     /**
      * Returns the resource store
-     * 
+     *
      * @return the resource store
      */
     public ResourceStore getStore() {
@@ -113,16 +113,16 @@
 
     /**
      * Returns the resource group manager
-     * 
+     *
      * @return the resource group manager
-     */    
+     */
     public ExternalResourceManager getExternalManager() {
         return this.external;
     }
 
     /**
      * Writes out all external resource groups that are held
-     * 
+     *
      * @throws java.io.IOException an I/O exception of some sort has occurred.
      */
     public void writeExternal() throws IOException {
@@ -131,8 +131,9 @@
 
     /**
      * Clears the store
+     * @throws IOException if an error occurs while clearing the resource store
      */
-    public void clearStore() {
+    public void clearStore() throws IOException {
         store.clear();
     }
 }

Modified: xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/modca/resource/ResourceStore.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/modca/resource/ResourceStore.java?rev=680923&r1=680922&r2=680923&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/modca/resource/ResourceStore.java (original)
+++ xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/modca/resource/ResourceStore.java Tue Jul 29 23:50:49 2008
@@ -5,9 +5,9 @@
  * The ASF licenses this file to You under the Apache License, Version 2.0
  * (the "License"); you may not use this file except in compliance with
  * the License.  You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -44,16 +44,16 @@
 
     /** Internal temporary storage buffer size */
     private static final int BUFFER_SIZE = 4096;
-        
+
     /** Used for storage of data objects */
     private RandomAccessFile raFile;
-    
+
     /** The temporary cache file */
     private File tempFile;
 
     /** The file outputstream */
     private FileOutputStream fos;
-    
+
     /**
      * Default constructor
      */
@@ -68,15 +68,18 @@
             log.error(e.getMessage());
         }
     }
-    
+
     /**
-     * Clears the data object cache
+     * Clears the data object cache.
+     * @throws IOException if an error occurs while clearing the store
      */
-    public void clear() {
+    public void clear() throws IOException {
         if (tempFile != null) {
-            if (!tempFile.delete()) {
-                // failed to delete to schedule so attempt to delete on exit from the VM
-                tempFile.deleteOnExit();
+            raFile.close();
+            raFile = null;
+            fos = null;
+            if (tempFile.exists() && !tempFile.delete()) {
+                throw new IOException("Could not delete temporary file: " + tempFile);
             }
             tempFile = null;
         }
@@ -90,13 +93,13 @@
             super.finalize();
         }
     }
-    
+
     /**
      * Stores a named data object in the cache
-     * 
+     *
      * @param dataObj a named data object
      * @return a new save information record
-     * 
+     *
      * @throws java.io.IOException an I/O exception of some sort has occurred.
      */
     public StoreInfo save(AbstractNamedAFPObject dataObj) throws IOException {
@@ -111,13 +114,13 @@
         storeInfo.size = (int)(raFile.getFilePointer() - storeInfo.position);
         return storeInfo;
     }
-    
+
     /**
      * Writes out the resource given the save information to the given outputstream.
-     * 
+     *
      * @param saveInfo the save information
      * @param os the outputstream to write to
-     * 
+     *
      * @throws java.io.IOException an I/O exception of some sort has occurred.
      */
     public void writeToStream(StoreInfo saveInfo, OutputStream os) throws IOException {
@@ -135,5 +138,5 @@
         raFile.read(buffer, 0, lastChunkLength);
         os.write(buffer, 0, lastChunkLength);
     }
-    
+
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org