2 * This file is part of the Vamsas Client version 0.2.
3 * Copyright 2010 by Jim Procter, Iain Milne, Pierre Marguerite,
4 * Andrew Waterhouse and Dominik Lindner.
6 * Earlier versions have also been incorporated into Jalview version 2.4
7 * since 2008, and TOPALi version 2 since 2007.
9 * The Vamsas Client is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU Lesser General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or
12 * (at your option) any later version.
14 * The Vamsas Client is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public License
20 * along with the Vamsas Client. If not, see <http://www.gnu.org/licenses/>.
22 package uk.ac.vamsas.client.simpleclient;
25 import java.io.FileOutputStream;
26 import java.io.FileReader;
27 import java.io.IOException;
28 import java.io.InputStream;
29 import java.io.InputStreamReader;
30 import java.io.PrintWriter;
31 import java.util.Timer;
32 import java.util.jar.JarEntry;
33 import java.util.jar.JarFile;
34 import java.util.jar.JarInputStream;
35 import java.util.jar.JarOutputStream;
38 * low level vamsas document management routines analogous to ClientsFile Grew
39 * out of io tests on VamsasArchive class in
40 * uk.ac.vamsas.test.simpleclient.VamsasArchive This class is not thread safe.
45 public class VamsasFile extends SessionFile {
48 * Connect to an existing Vamsas document in a given sessionDir or create a
52 * @throws java.io.IOException
54 public VamsasFile(File sessionFile) throws java.io.IOException {
60 * @return the VamsasFile
62 public File getVamsasFile() {
67 * Expand a previously stored session into the sessionDir
70 * @param storedSession
71 * public VamsasFile(File sessionDir, JarFile storedSession) throws
72 * IOException { // check if sessionDir is live or not if
73 * (!sessionDir.exists()) { sessionDir.mkdir(); }
75 * { // check its actually a writable directory }
77 * File sfile = new File(sessionDir, "vamsas.jar");
78 * VamsasFile(sfile); // if live - try to merge storedSession with
79 * sessionDir // - will probably fail through duplicate Vobject
80 * references needing to be dereferenced. // TODO: think of a way of
81 * specifying vorba_id scope for an application's references to allow
82 * merging of one vamsasDocument with another.
87 * public interface for getting a lock. The lock object is internally
88 * referenced so the lock will persist even after the return value of the
89 * method goes out of scope.
91 * @return null if lock couldn't be got or a valid Lock object.
93 public Lock getLock() {
102 * @return null, extantLock or new Lock.
104 public Lock getLock(Lock extantLock) {
105 if (lockFile(extantLock))
111 * explicitly unlocks vamsas file. if you have called getLock() you *must*
112 * call this to release the lock.
114 public void unLock() {