01: // DelayedInputStream.java
02: // $Id: DelayedInputStream.java,v 1.5 2000/08/16 21:37:46 ylafon Exp $
03: // (c) COPYRIGHT MIT and INRIA, 1996.
04: // Please first read the full copyright statement in file COPYRIGHT.html
05:
06: package org.w3c.jigsaw.ssi;
07:
08: import java.io.IOException;
09: import java.io.InputStream;
10:
11: /**
12: * Used to delay the (perhaps expensive) creation of a real stream
13: * until the first access.
14: * @author Antonio Ramirez <anto@mit.edu>
15: */
16:
17: public abstract class DelayedInputStream extends InputStream {
18:
19: /**
20: * The InputStream that data will be really read from.
21: */
22: protected InputStream in = null;
23:
24: /**
25: * This method is called on the first access to the stream.
26: * (<em>Not</em> at construction time.) Should initialize
27: * <code>in</code> as a valid stream. Must <em>not</em> make it
28: * <strong>null</strong>.
29: */
30: protected abstract void init();
31:
32: public final void close() throws IOException {
33: if (in != null)
34: in.close();
35: }
36:
37: public final int read() throws IOException {
38: if (in == null)
39: init();
40: return in.read();
41: }
42:
43: public final int read(byte b[], int off, int len)
44: throws IOException {
45: if (in == null)
46: init();
47: return in.read(b, off, len);
48: }
49:
50: public final int read(byte b[]) throws IOException {
51: if (in == null)
52: init();
53: return in.read(b);
54: }
55:
56: public final void reset() throws IOException {
57: if (in == null)
58: init();
59: in.reset();
60: }
61:
62: public final void mark(int readlimit) {
63: if (in == null)
64: init();
65: in.mark(readlimit);
66: }
67:
68: public final boolean markSupported() {
69: if (in == null)
70: init();
71: return in.markSupported();
72: }
73:
74: public final long skip(long n) throws IOException {
75: if (in == null)
76: init();
77: return in.skip(n);
78: }
79:
80: public final int available() throws IOException {
81: if (in == null)
82: init();
83: return in.available();
84: }
85:
86: }
|