< prev index next >

src/java.base/share/classes/java/io/SequenceInputStream.java

Print this page
rev 15357 : imported patch 8163517-Various-cleanup-in-java-io-code

*** 63,78 **** * @param e an enumeration of input streams. * @see java.util.Enumeration */ public SequenceInputStream(Enumeration<? extends InputStream> e) { this.e = e; ! try { ! nextStream(); ! } catch (IOException ex) { ! // This should never happen ! throw new Error("panic"); ! } } /** * Initializes a newly * created <code>SequenceInputStream</code> --- 63,73 ---- * @param e an enumeration of input streams. * @see java.util.Enumeration */ public SequenceInputStream(Enumeration<? extends InputStream> e) { this.e = e; ! peekNextStream(); } /** * Initializes a newly * created <code>SequenceInputStream</code>
*** 84,120 **** * @param s1 the first input stream to read. * @param s2 the second input stream to read. */ public SequenceInputStream(InputStream s1, InputStream s2) { Vector<InputStream> v = new Vector<>(2); - v.addElement(s1); v.addElement(s2); e = v.elements(); ! try { ! nextStream(); ! } catch (IOException ex) { ! // This should never happen ! throw new Error("panic"); ! } } /** * Continues reading in the next stream if an EOF is reached. */ final void nextStream() throws IOException { if (in != null) { in.close(); } if (e.hasMoreElements()) { in = (InputStream) e.nextElement(); if (in == null) throw new NullPointerException(); } - else in = null; - } /** * Returns an estimate of the number of bytes that can be read (or * skipped over) from the current underlying input stream without --- 79,112 ---- * @param s1 the first input stream to read. * @param s2 the second input stream to read. */ public SequenceInputStream(InputStream s1, InputStream s2) { Vector<InputStream> v = new Vector<>(2); v.addElement(s1); v.addElement(s2); e = v.elements(); ! peekNextStream(); } /** * Continues reading in the next stream if an EOF is reached. */ final void nextStream() throws IOException { if (in != null) { in.close(); } + peekNextStream(); + } + private void peekNextStream() { if (e.hasMoreElements()) { in = (InputStream) e.nextElement(); if (in == null) throw new NullPointerException(); + } else { + in = null; } } /** * Returns an estimate of the number of bytes that can be read (or * skipped over) from the current underlying input stream without
< prev index next >