+ /**
+ * copy data from the appData jar file to an appropriately
+ * referenced jar or Data entry for the given ApplicationData
+ * Assumes the JarFile is properly closed.
+ * @param vdoc session Document handler
+ * @param appd the AppData whose block is being updated
+ * @param apdjar the new data in a Jar written by this class
+ */
+ protected void updateAnAppdataEntry(VamsasArchive vdoc, AppData appd, SessionFile apdjar) throws IOException {
+ if (apdjar==null || apdjar.sessionFile==null || !apdjar.sessionFile.exists()) {
+ throw new IOException("No temporary Appdata to recover and transfer.");
+ }
+ if (vdoc==null) {
+ log.fatal("FATAL! NO DOCUMENT TO WRITE TO!");
+ throw new IOException("FATAL! NO DOCUMENT TO WRITE TO!");
+ }
+ log.debug("Recovering AppData entry from "+apdjar.sessionFile);
+ JarInputStream istrm = new JarInputStream(new BufferedInputStream(new FileInputStream(apdjar.sessionFile)));
+ JarEntry je=null;
+ while (istrm.available()>0 && (je=istrm.getNextJarEntry())!=null && !je.getName().equals("appData_entry.dat")) {
+ if (je!=null)
+ log.debug("Ignoring extraneous entry "+je.getName());
+ }
+ if (istrm.available()>0 && je!=null) {
+ log.debug("Found appData_entry.dat in Jar");
+ String ref = appd.getDataReference();
+ if (ref==null) {
+ throw new IOException("Null AppData.DataReference passed.");
+ }
+ if (vdoc.writeAppdataFromStream(ref, istrm)) {
+ log.debug("Entry updated successfully.");
+ } else {
+ throw new IOException("writeAppdataFromStream did not return true - expect future badness."); // LATER - verify why this might occur.
+ }
+ } else {
+ throw new IOException("Couldn't find appData_entry.dat in temporary jar file "+apdjar.sessionFile.getAbsolutePath());
+ }
+ istrm.close();
+ }