applied LGPLv3 and source code formatting.
[vamsas.git] / src / uk / ac / vamsas / client / AppDataInputStream.java
1 /*\r
2  * This file is part of the Vamsas Client version 0.1. \r
3  * Copyright 2009 by Jim Procter, Iain Milne, Pierre Marguerite, \r
4  *  Andrew Waterhouse and Dominik Lindner.\r
5  * \r
6  * Earlier versions have also been incorporated into Jalview version 2.4 \r
7  * since 2008, and TOPALi version 2 since 2007.\r
8  * \r
9  * The Vamsas Client is free software: you can redistribute it and/or modify\r
10  * it under the terms of the GNU Lesser General Public License as published by\r
11  * the Free Software Foundation, either version 3 of the License, or\r
12  * (at your option) any later version.\r
13  *  \r
14  * The Vamsas Client is distributed in the hope that it will be useful,\r
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
17  * GNU Lesser General Public License for more details.\r
18  * \r
19  * You should have received a copy of the GNU Lesser General Public License\r
20  * along with the Vamsas Client.  If not, see <http://www.gnu.org/licenses/>.\r
21  */\r
22 package uk.ac.vamsas.client;\r
23 \r
24 import java.io.DataInput;\r
25 import java.io.DataInputStream;\r
26 import java.io.IOException;\r
27 import java.io.InputStream;\r
28 import java.util.jar.JarInputStream;\r
29 \r
30 import org.apache.commons.logging.Log;\r
31 import org.apache.commons.logging.LogFactory;\r
32 \r
33 /**\r
34  * @author jimp LATER: this may not be a necessary or useful class to return\r
35  *         from IClientAppdata get*InputStream() methods\r
36  */\r
37 public class AppDataInputStream extends DataInputStream implements DataInput {\r
38   private Log log = LogFactory.getLog(AppDataInputStream.class);\r
39 \r
40   private boolean isOpen = false;\r
41 \r
42   /**\r
43    * Wrapper for writing to/from AppData Entries in a Vamsas Document.\r
44    */\r
45   public AppDataInputStream(InputStream inputstream) {\r
46     super(inputstream);\r
47     isOpen = true;\r
48   }\r
49 \r
50   /*\r
51    * (non-Javadoc)\r
52    * \r
53    * @see java.io.FilterInputStream#close()\r
54    */\r
55   public void close() throws IOException {\r
56     if (!isOpen) {\r
57       log.debug("close() called on closed AppDataInputStream.");\r
58       // throw new\r
59       // IOException("Attempt to close an already closed AppDataInputStream");\r
60     } else {\r
61       isOpen = false;\r
62     }\r
63   }\r
64 \r
65   /**\r
66    * Will return zero if stream has been closed.\r
67    * \r
68    * @see java.io.FilterInputStream#available()\r
69    */\r
70   public int available() throws IOException {\r
71     if (isOpen)\r
72       return super.available();\r
73     else\r
74       return 0;\r
75   }\r
76 \r
77 }\r