KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sapia > ubik > util > ByteVectorInputStream


1 package org.sapia.ubik.util;
2
3 import java.io.IOException JavaDoc;
4 import java.io.InputStream JavaDoc;
5
6
7 /**
8  * This class implements an <code>InputStream</code> over the <code>ByteVector</code>
9  * class.
10  * <p>
11  * The <code>close()</code> method has no effect on an instance of this class. The
12  * underlying ByteVector can be read from repetitively. If it must be re-read from
13  * the beginning, then the vector's <code>reset()</code> method must be called.
14  * <p>
15  * <b>WARNING: THIS CLASS IS NOT THREAD-SAFE</b>.
16  *
17  * @see ByteVectorOutputStream
18  *
19  * @author Yanick Duchesne
20  *
21  * <dl>
22  * <dt><b>Copyright:</b><dd>Copyright &#169; 2002-2005 <a HREF="http://www.sapia-oss.org">Sapia Open Source Software</a>. All Rights Reserved.</dd></dt>
23  * <dt><b>License:</b><dd>Read the license.txt file of the jar or visit the
24  * <a HREF="http://www.sapia-oss.org/license.html">license page</a> at the Sapia OSS web site</dd></dt>
25  * </dl>
26  */

27 public class ByteVectorInputStream extends InputStream JavaDoc{
28   
29   private ByteVector _bytes;
30   
31   public ByteVectorInputStream(ByteVector bytes){
32     _bytes = bytes;
33   }
34   public ByteVector getByteVector(){
35     return _bytes;
36   }
37   
38   /**
39    * @see java.io.InputStream#available()
40    */

41   public int available() throws IOException JavaDoc {
42     return _bytes.remaining();
43   }
44   
45   /**
46    * @see java.io.InputStream#close()
47    */

48   public void close() throws IOException JavaDoc {
49   }
50   
51   /**
52    * @see java.io.InputStream#mark(int)
53    */

54   public synchronized void mark(int readlimit) {
55     _bytes.mark(readlimit);
56   }
57   
58   /**
59    * @see java.io.InputStream#markSupported()
60    */

61   public boolean markSupported() {
62     return true;
63   }
64   
65   /**
66    * @see java.io.InputStream#read()
67    */

68   public int read() throws IOException JavaDoc {
69     return _bytes.read();
70   }
71   
72   /**
73    * @see java.io.InputStream#read(byte[], int, int)
74    */

75   public int read(byte[] b, int off, int len) throws IOException JavaDoc {
76     int read = _bytes.read(b, off, len);
77     return read == 0 ? -1 : read;
78   }
79   
80   /**
81    * @see java.io.InputStream#read(byte[])
82    */

83   public int read(byte[] b) throws IOException JavaDoc {
84     int read = _bytes.read(b);
85     return read == 0 ? -1 : read;
86   }
87   
88   /**
89    * @see java.io.InputStream#reset()
90    */

91   public synchronized void reset() throws IOException JavaDoc {
92     _bytes.reset();
93   }
94   
95   /**
96    * @see java.io.InputStream#skip(long)
97    */

98   public long skip(long n) throws IOException JavaDoc {
99     return _bytes.skip(n);
100   }
101 }
102
Popular Tags