JDK-6322836 : provide SequenceInputStream(List) constructor
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.io
  • Affected Version: 5.0
  • Priority: P5
  • Status: Open
  • Resolution: Unresolved
  • Submitted: 2005-09-12
  • Updated: 2017-07-20
Related Reports
Relates :  
java.io.SequenceInputStream has two constructors: an Enumeration, and two other input streams.

It would be good if it supported varargs.

Enumeration is rather old these days, and is discouraged. As the enumeration is simply a way to provide multiple input streams, varargs support would be cleaner and more typesafe.

This is also consistent with Bug 4183159, which suggests adding a ListIterator constructor.

See http://twasink.net/blog/archives/2005/09/xml_javaio_and_1.html for a real-world scenario where this would have helped.

Well, one obvious workaround is to implement a factory method like so:

InputStream sequenceStreams(InputStream ... streamsToSequence) {
  return new SequenceInputStream(Collections.enumeration(Arrays.asList(streamsToSequence)));

As noted, an Enumeration is fairly old and is inconvenient to use. A varargs constructor would be somewhat helpful. A brief grepcode search revealed a fair number of uses, so it might be worth considering enhancing SequenceInputStream a little bit. However, if we were to add anything, I'd suggest: SequenceInputStream(List<? extends InputStream>) The varargs case can be handled by writing new SequenceInputStream(List.of(is1, is2, is3, ...)) Alternatives might be SequenceInputStream(Collection<? extends InputStream>) SequenceInputStream(Iterable<? extends InputStream>) SequenceInputStream(Iterator<? extends InputStream>) SequenceInputStream(Stream<? extends InputStream>) Iterable and Iterator are generally not used in JDK APIs to represent zero-or-more elements; Collection usually is. A collection might be a set (or possibly a bag/multiset) which are generally unordered, so sequencing semantics would be ill-defined. A Stream of InputStreams would be quite odd; most likely its source would be an ordered collection, which is probably a List in the first place. So, I recommend adding one constructor taking a List. It's unclear whether it's worth deprecating SequenceInputStream(Enumeration<? extends InputStream).