< 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,16 +63,11 @@
      * @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");
-        }
+        peekNextStream();
     }
 
     /**
      * Initializes a newly
      * created <code>SequenceInputStream</code>

@@ -84,37 +79,34 @@
      * @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");
-        }
+        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;
         }
-        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 >