23 * questions.
24 */
25
26 package java.io;
27
28 import java.io.InputStream;
29 import java.util.Enumeration;
30 import java.util.Vector;
31
32 /**
33 * A <code>SequenceInputStream</code> represents
34 * the logical concatenation of other input
35 * streams. It starts out with an ordered
36 * collection of input streams and reads from
37 * the first one until end of file is reached,
38 * whereupon it reads from the second one,
39 * and so on, until end of file is reached
40 * on the last of the contained input streams.
41 *
42 * @author Author van Hoff
43 * @since JDK1.0
44 */
45 public
46 class SequenceInputStream extends InputStream {
47 Enumeration<? extends InputStream> e;
48 InputStream in;
49
50 /**
51 * Initializes a newly created <code>SequenceInputStream</code>
52 * by remembering the argument, which must
53 * be an <code>Enumeration</code> that produces
54 * objects whose run-time type is <code>InputStream</code>.
55 * The input streams that are produced by
56 * the enumeration will be read, in order,
57 * to provide the bytes to be read from this
58 * <code>SequenceInputStream</code>. After
59 * each input stream from the enumeration
60 * is exhausted, it is closed by calling its
61 * <code>close</code> method.
62 *
63 * @param e an enumeration of input streams.
115
116 }
117
118 /**
119 * Returns an estimate of the number of bytes that can be read (or
120 * skipped over) from the current underlying input stream without
121 * blocking by the next invocation of a method for the current
122 * underlying input stream. The next invocation might be
123 * the same thread or another thread. A single read or skip of this
124 * many bytes will not block, but may read or skip fewer bytes.
125 * <p>
126 * This method simply calls {@code available} of the current underlying
127 * input stream and returns the result.
128 *
129 * @return an estimate of the number of bytes that can be read (or
130 * skipped over) from the current underlying input stream
131 * without blocking or {@code 0} if this input stream
132 * has been closed by invoking its {@link #close()} method
133 * @exception IOException if an I/O error occurs.
134 *
135 * @since JDK1.1
136 */
137 public int available() throws IOException {
138 if (in == null) {
139 return 0; // no way to signal EOF from available()
140 }
141 return in.available();
142 }
143
144 /**
145 * Reads the next byte of data from this input stream. The byte is
146 * returned as an <code>int</code> in the range <code>0</code> to
147 * <code>255</code>. If no byte is available because the end of the
148 * stream has been reached, the value <code>-1</code> is returned.
149 * This method blocks until input data is available, the end of the
150 * stream is detected, or an exception is thrown.
151 * <p>
152 * This method
153 * tries to read one character from the current substream. If it
154 * reaches the end of the stream, it calls the <code>close</code>
155 * method of the current substream and begins reading from the next
|
23 * questions.
24 */
25
26 package java.io;
27
28 import java.io.InputStream;
29 import java.util.Enumeration;
30 import java.util.Vector;
31
32 /**
33 * A <code>SequenceInputStream</code> represents
34 * the logical concatenation of other input
35 * streams. It starts out with an ordered
36 * collection of input streams and reads from
37 * the first one until end of file is reached,
38 * whereupon it reads from the second one,
39 * and so on, until end of file is reached
40 * on the last of the contained input streams.
41 *
42 * @author Author van Hoff
43 * @since 1.0
44 */
45 public
46 class SequenceInputStream extends InputStream {
47 Enumeration<? extends InputStream> e;
48 InputStream in;
49
50 /**
51 * Initializes a newly created <code>SequenceInputStream</code>
52 * by remembering the argument, which must
53 * be an <code>Enumeration</code> that produces
54 * objects whose run-time type is <code>InputStream</code>.
55 * The input streams that are produced by
56 * the enumeration will be read, in order,
57 * to provide the bytes to be read from this
58 * <code>SequenceInputStream</code>. After
59 * each input stream from the enumeration
60 * is exhausted, it is closed by calling its
61 * <code>close</code> method.
62 *
63 * @param e an enumeration of input streams.
115
116 }
117
118 /**
119 * Returns an estimate of the number of bytes that can be read (or
120 * skipped over) from the current underlying input stream without
121 * blocking by the next invocation of a method for the current
122 * underlying input stream. The next invocation might be
123 * the same thread or another thread. A single read or skip of this
124 * many bytes will not block, but may read or skip fewer bytes.
125 * <p>
126 * This method simply calls {@code available} of the current underlying
127 * input stream and returns the result.
128 *
129 * @return an estimate of the number of bytes that can be read (or
130 * skipped over) from the current underlying input stream
131 * without blocking or {@code 0} if this input stream
132 * has been closed by invoking its {@link #close()} method
133 * @exception IOException if an I/O error occurs.
134 *
135 * @since 1.1
136 */
137 public int available() throws IOException {
138 if (in == null) {
139 return 0; // no way to signal EOF from available()
140 }
141 return in.available();
142 }
143
144 /**
145 * Reads the next byte of data from this input stream. The byte is
146 * returned as an <code>int</code> in the range <code>0</code> to
147 * <code>255</code>. If no byte is available because the end of the
148 * stream has been reached, the value <code>-1</code> is returned.
149 * This method blocks until input data is available, the end of the
150 * stream is detected, or an exception is thrown.
151 * <p>
152 * This method
153 * tries to read one character from the current substream. If it
154 * reaches the end of the stream, it calls the <code>close</code>
155 * method of the current substream and begins reading from the next
|