+ private DataOutput _getAppdataOutputStream(boolean clientOrUser) {
+ String apdname;
+ SessionFile apdfile=null;
+ if (!clientOrUser) {
+ apdname = "clientAppData";
+ apdfile = newAppData;
+ } else {
+ apdname = "userAppData";
+ apdfile = newUserData;
+ }
+ try {
+ if (apdfile==null) {
+ apdfile=clientdoc.sclient._session.getTempSessionFile(apdname,".jar");
+ log.debug("Successfully made temp appData file for "+apdname);
+ } else {
+ // truncate to remove existing data.
+ apdfile.fileLock.rafile.setLength(0);
+ log.debug("Successfully truncated existing temp appData for "+apdname);
+ }
+ } catch (Exception e) {
+ log.error("Whilst opening temp file in directory "+clientdoc.sclient._session.sessionDir, e);
+ }
+ // we do not make another file for the new entry if one exists already
+ if (!clientOrUser) {
+ newAppData = apdfile;
+ } else {
+ newUserData = apdfile;
+ }
+ try {
+ apdfile.lockFile();
+ JarOutputStream dstrm =
+ new JarOutputStream(
+ new BufferedOutputStream(new java.io.FileOutputStream(apdfile.sessionFile)));
+ if (!clientOrUser) {
+ newAppDataStream = dstrm;
+ } else {
+ newUserDataStream = dstrm;
+ }
+ dstrm.putNextEntry(new JarEntry("appData_entry.dat"));
+ // LATER: there may be trouble ahead if an AppDataOutputStream is written to by one thread when another truncates the file. This situation should be prevented if possible
+ return new AppDataOutputStream(dstrm);
+ }
+ catch (Exception e) {
+ log.error("Whilst opening jar output stream for file "+apdfile.sessionFile);
+ }
+ // tidy up and return null
+ apdfile.unlockFile();
+ return null;
+ }