0b021aabc5bb962137517920c9588a1bbd909c3f
[vamsas.git] / src / uk / ac / vamsas / client / AppDataInputStream.java
1 /**
2  * 
3  */
4 package uk.ac.vamsas.client;
5
6 import java.io.DataInput;
7 import java.io.DataInputStream;
8 import java.io.IOException;
9 import java.io.InputStream;
10 import java.util.jar.JarInputStream;
11
12 import org.apache.commons.logging.Log;
13 import org.apache.commons.logging.LogFactory;
14
15 /**
16  * @author jimp
17  * LATER: this may not be a necessary or useful class to return from IClientAppdata get*InputStream() methods
18  */
19 public class AppDataInputStream extends DataInputStream implements DataInput {
20   private Log log = LogFactory.getLog(AppDataInputStream.class);
21   private boolean isOpen = false;
22   /**
23    * Wrapper for writing to/from AppData Entries in a Vamsas Document.
24    */
25   public AppDataInputStream(InputStream inputstream) {
26     super(inputstream);
27     isOpen=true;
28   }
29
30   /* (non-Javadoc)
31    * @see java.io.FilterInputStream#close()
32    */
33   public void close() throws IOException {
34     if (!isOpen) {
35       log.debug("close() called on closed AppDataInputStream.");
36       // throw new IOException("Attempt to close an already closed AppDataInputStream");
37     } else {
38       isOpen=false;
39     }
40   }
41
42   /**
43    * Will return zero if stream has been closed.
44    * @see java.io.FilterInputStream#available()
45    */
46   public int available() throws IOException {
47     if (isOpen)
48       return super.available();
49     else
50       return 0;
51   }
52   
53 }