* @throws IOException if call to accessOriginal failed for updates, or openArchive failed.
*/
public VamsasArchive(File archive, boolean vamsasdocument) throws IOException {
+ this(archive, vamsasdocument, null);
+ }
+ public VamsasArchive(File archive, boolean vamsasdocument, Lock extantLock) throws IOException {
super();
+
if (archive==null || (archive!=null && !(archive.getParentFile().canWrite() && (!archive.exists() || archive.canWrite())))) {
log.fatal("Expect Badness! -- Invalid parameters for VamsasArchive constructor:"+((archive!=null)
? "File cannot be overwritten." : "Null Object not valid constructor parameter"));
this.vamsasdocument = vamsasdocument;
if (archive.exists()) {
this.original = archive;
+ this.odoclock = new SessionFile(archive); // lock the file *immediatly*
+ odoclock.lockFile(extantLock);
this.archive = null; // archive will be a temp file when the open method is called
virginArchive=false;
try {
} else {
this.original = null;
this.archive = archive; // archive is written in place.
+ if (archive!=null) {
+ archive.createNewFile();
+ rchive=new SessionFile(archive); // lock the file *immediatly*
+ rchive.lockFile(extantLock);
+ }
virginArchive = true;
}
this.openArchive(); // open archive
* opens the new archive ready for writing. If the new archive is replacing an existing one,
* then the existing archive will be locked, and the new archive written to a temporary file.
* The new archive will be put in place once close() is called.
+ * @param doclock TODO
* @throws IOException
*/
private void openArchive() throws IOException {
log.warn("New archive file name already in use! Possible lock failure imminent?");
}
- rchive = new SessionFile(archive);
- rchive.lockFile();
+ if (rchive==null)
+ rchive = new SessionFile(archive);
+ archive.createNewFile();
+ if (!rchive.lockFile())
+ throw new IOException("Failed to get lock on file "+archive);
+
newarchive = new JarOutputStream(new BufferedOutputStream(new java.io.FileOutputStream(archive)));
entries = new Hashtable();
}
*/
public AppDataOutputStream getAppDataStream(String appdataReference) throws IOException {
if (newarchive==null)
- openArchive();
+ throw new IOException("Attempt to write to closed VamsasArchive object.");
if (addValidEntry(appdataReference)) {
return new AppDataOutputStream(newarchive);
}
private void closeAndReset() {
if (rchive!=null) {
rchive.unlockFile();
- rchive = null;
+ rchive=null;
}
if (original!=null) {
if (odoc!=null) {