From 58ced019430c430493a13d2a75dae6f604a4a78a Mon Sep 17 00:00:00 2001 From: jprocter Date: Fri, 24 Mar 2006 19:16:26 +0000 Subject: [PATCH] fixed (hopefully) locking/read problems in test.simpleclient.VamsasArchive/Watcher classes and commented out the RandomAccess based reading/writing for mo. git-svn-id: https://svn.lifesci.dundee.ac.uk/svn/repository/trunk@212 be28352e-c001-0410-b1a7-c7978e42abec --- .../vamsas/client/simpleclient/VamsasArchive.java | 12 ++++++---- .../client/simpleclient/VamsasArchiveReader.java | 25 ++++++++++++-------- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/src/org/vamsas/client/simpleclient/VamsasArchive.java b/src/org/vamsas/client/simpleclient/VamsasArchive.java index 6e8138b..d769a5c 100644 --- a/src/org/vamsas/client/simpleclient/VamsasArchive.java +++ b/src/org/vamsas/client/simpleclient/VamsasArchive.java @@ -196,6 +196,7 @@ public class VamsasArchive { */ public VamsasArchive(VamsasFile archive, boolean vamsasdocument, boolean overwrite) throws IOException { this(archive.sessionFile, overwrite, vamsasdocument, archive); + log.debug("using non-functional lock-IO stream jar access constructor"); } /** * @@ -256,7 +257,8 @@ public class VamsasArchive { odoclock = new SessionFile(original); odoclock.lockFile(); if (odoc == null) - odoc = new VamsasArchiveReader(odoclock.fileLock); + odoc = new VamsasArchiveReader(original); + // this constructor is not implemented yet odoc = new VamsasArchiveReader(odoclock.fileLock); } } @@ -373,7 +375,7 @@ public class VamsasArchive { newarchive.closeEntry(); if (!isDocumentWritten()) log.warn("Premature closure of archive '"+archive.getAbsolutePath()+"': No document has been written."); - newarchive.finish(); + newarchive.close(); // use newarchive.finish(); for a stream IO updateOriginal(); closeAndReset(); } else { @@ -552,8 +554,10 @@ public class VamsasArchive { rchive = new SessionFile(archive); if (!rchive.lockFile()) throw new IOException("Failed to get lock on file "+archive); - Manifest newmanifest = new Manifest(); - newarchive = new JarOutputStream(rchive.fileLock.getBufferedOutputStream(true), newmanifest); + // LATER: locked IO stream based access. + //Manifest newmanifest = new Manifest(); + //newarchive = new JarOutputStream(rchive.fileLock.getBufferedOutputStream(true), newmanifest); + newarchive = new JarOutputStream(new BufferedOutputStream(new java.io.FileOutputStream(archive))); entries = new Hashtable(); } public void putVamsasDocument(VamsasDocument doc) throws IOException, diff --git a/src/org/vamsas/client/simpleclient/VamsasArchiveReader.java b/src/org/vamsas/client/simpleclient/VamsasArchiveReader.java index d0476cd..b4455ac 100644 --- a/src/org/vamsas/client/simpleclient/VamsasArchiveReader.java +++ b/src/org/vamsas/client/simpleclient/VamsasArchiveReader.java @@ -35,7 +35,8 @@ public class VamsasArchiveReader { ZipInputStream jstream=null; Hashtable strmentries = null; private void streamInit() { - if (!stream) { + throw new Error("VamsasArchiveReader(Stream) Not implemented!"); + /* if (!stream) { log.debug("Skipping init for Jar Stream input."); return; } @@ -48,13 +49,13 @@ public class VamsasArchiveReader { if (jstream.available()==0) log.warn("Can't read from JarInputStream (Locked stream!)"); ZipEntry entry=null; + long pos=0; do { - long pos = rfile.getFilePointer(); if ((entry=jstream.getNextEntry())!=null) { if (strmentries.containsKey(entry.getName())) { log.info("Only recording last of duplicate entries '"+entry.getName()+"'"); } - strmentries.put(entry.getName(), new Long(pos)); + strmentries.put(entry.getName(), new Long(pos++)); jstream.closeEntry(); } } while (entry!=null); @@ -62,7 +63,7 @@ public class VamsasArchiveReader { catch (Exception e) { log.warn("Exceptions during init!",e); jstream=null; - } + }*/ } public VamsasArchiveReader(File vamsasfile) { @@ -85,11 +86,13 @@ public class VamsasArchiveReader { * @param vamsaslock */ public VamsasArchiveReader(Lock vamsaslock) { - rfile = vamsaslock.rafile; - stream = true; - streamInit(); - if (jstream==null) - throw new Error("Failed to open archive from Locked random access stream."); + // LATER: implement or remove + throw new Error("VamsasArchiveReading from locked IO stream not yet implemented."); + //rfile = vamsaslock.rafile; + //stream = true; + //streamInit(); + //if (jstream==null) + // throw new Error("Failed to open archive from Locked random access stream."); } /** @@ -124,7 +127,9 @@ public class VamsasArchiveReader { return null; } try { - jstream.reset(); + jstream=null; + rfile.seek(0); + jstream = new ZipInputStream(new FileInputStream(rfile.getFD())); ZipEntry entry = null; long epos = entrypos.longValue(); do { -- 1.7.10.2