aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/org/apache/fop/render
diff options
context:
space:
mode:
authorJeremias Maerki <jeremias@apache.org>2008-07-30 06:50:49 +0000
committerJeremias Maerki <jeremias@apache.org>2008-07-30 06:50:49 +0000
commitd71f26e615fb573e19786a8297959dbb0f5741ef (patch)
tree9b09a274ff82a32210ed37004397d11f701a0a6a /src/java/org/apache/fop/render
parentfd378f8734e995e649dda935105fdd72353083e0 (diff)
downloadxmlgraphics-fop-d71f26e615fb573e19786a8297959dbb0f5741ef.tar.gz
xmlgraphics-fop-d71f26e615fb573e19786a8297959dbb0f5741ef.zip
Bugfix: ResourceStore didn't close the RandomAccessFile and therefore couldn't close the temporary file. Not even deleteOnExit() can help in that case.
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/Temp_AFPGOCAResources@680923 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache/fop/render')
-rw-r--r--src/java/org/apache/fop/render/afp/modca/resource/ResourceManager.java35
-rw-r--r--src/java/org/apache/fop/render/afp/modca/resource/ResourceStore.java39
2 files changed, 39 insertions, 35 deletions
diff --git a/src/java/org/apache/fop/render/afp/modca/resource/ResourceManager.java b/src/java/org/apache/fop/render/afp/modca/resource/ResourceManager.java
index 60cbb7257..01368fa07 100644
--- a/src/java/org/apache/fop/render/afp/modca/resource/ResourceManager.java
+++ b/src/java/org/apache/fop/render/afp/modca/resource/ResourceManager.java
@@ -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.AbstractNamedAFPObject;
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 @@ public class ResourceManager {
/** 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 @@ public class ResourceManager {
}
/**
- * 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 @@ public class ResourceManager {
/**
* Returns the resource factory
- *
+ *
* @return the resource factory
*/
public ResourceFactory getFactory() {
@@ -104,7 +104,7 @@ public class ResourceManager {
/**
* Returns the resource store
- *
+ *
* @return the resource store
*/
public ResourceStore getStore() {
@@ -113,16 +113,16 @@ public class ResourceManager {
/**
* 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 @@ public class ResourceManager {
/**
* Clears the store
+ * @throws IOException if an error occurs while clearing the resource store
*/
- public void clearStore() {
+ public void clearStore() throws IOException {
store.clear();
}
}
diff --git a/src/java/org/apache/fop/render/afp/modca/resource/ResourceStore.java b/src/java/org/apache/fop/render/afp/modca/resource/ResourceStore.java
index cec528c54..edec749d5 100644
--- a/src/java/org/apache/fop/render/afp/modca/resource/ResourceStore.java
+++ b/src/java/org/apache/fop/render/afp/modca/resource/ResourceStore.java
@@ -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 @@ public final class ResourceStore {
/** 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 @@ public final class ResourceStore {
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 @@ public final class ResourceStore {
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 @@ public final class ResourceStore {
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 @@ public final class ResourceStore {
raFile.read(buffer, 0, lastChunkLength);
os.write(buffer, 0, lastChunkLength);
}
-
+
}