1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.backsource.utils.io;
21 import java.io.InputStream;
22 import java.io.BufferedInputStream;
23 import java.io.IOException;
24 /***
25 * This is an InputStream that reads from cached data it will get
26 * from a CachedOutputStream.
27 *
28 * <p>The stream is therefore possible to reuse, after rewind has
29 been invoked.</p>
30 * <p>To be able to use these cinds of input stream with external API:s, such as the apache JAXP imlementation, the close method does nothing. To really close the stream use {@link #close(boolean)}.</p>
31 *
32 * @author <a href="mailto:pra@tim.se">Peter Antman</a>
33 * @version $Revision: 1.1.1.1 $
34 */
35
36 public abstract class CachedInputStream extends BufferedInputStream {
37 public CachedInputStream(InputStream is) {
38 super(is);
39 }
40
41 /***
42 * Does not close stream, to close an CachedInputStream use close(true).
43 */
44 public void close() throws IOException {
45 close(false);
46 }
47
48 /***
49 * Close the input stream if argument is true.
50 */
51 public void close(boolean reallyClose) throws IOException {
52 if ( reallyClose) {
53 super.close();
54 }
55
56 }
57
58 /***
59 * rewind the cached input stream so that next read starts from the beginning.
60 */
61 public abstract void rewind() throws IOException;
62
63 }