* 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.
* limitations under the License.
*/
-/* $Id: $ */
+/* $Id$ */
package org.apache.fop.render.afp.modca.resource;
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 */
/** 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
*/
}
/**
- * 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 {
/**
* Returns the resource factory
- *
+ *
* @return the resource factory
*/
public ResourceFactory getFactory() {
/**
* Returns the resource store
- *
+ *
* @return the resource store
*/
public ResourceStore getStore() {
/**
* 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 {
/**
* Clears the store
+ * @throws IOException if an error occurs while clearing the resource store
*/
- public void clearStore() {
+ public void clearStore() throws IOException {
store.clear();
}
}
* 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.
/** 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
*/
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;
}
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 {
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 {
raFile.read(buffer, 0, lastChunkLength);
os.write(buffer, 0, lastChunkLength);
}
-
+
}