Hi All! So `SequenceInputStream()` takes a Java `E...
# getting-started
a
Hi All! So
SequenceInputStream()
takes a Java
Enumeration
as an argument, but at the moment I only have a `List<InputStream>`; there's a workaround for this described at https://www.pushing-pixels.org/2018/08/15/converting-list-to-enumeration-in-kotlin.html to provide a
List<T>.toEnumeration()
method, but I am wondering if there's something more elegant?
v
More elegant, but less performant as it will create n-1
Vector
instances:
Copy code
inList.reduce { left, right -> SequenceInputStream(left, right) }
Another way would be
Copy code
SequenceInputStream(Vector(inList).elements())
❤️ 1
a
Thanks, @Vampire
Looks like this might be an RFE?
v
An
asEnumeration()
method? Maybe
n
I made this:
Copy code
private operator fun InputStream.plus(inputStream: InputStream): InputStream = SequenceInputStream(this, inputStream)
might be what you want
v
Well, that's neat and probably enables
inList.sum()
, but it is basically the same as my reduce call and thus will create n-1 new
Vector
instances.
n
it doesn't create any
Vector
instances though
v
Sure it does, look inside the
SequenceInputStream
constructor you are calling 😉
n
and it does indeed use a Vector
v
The first link you gave was the implementation of GNU classpath which I was not even aware of. 😄
I just navigated to the constructor from my IDE
Of course this is an implementation detail and could be different in different implementations as you just have proved. 🙂
n
I feel like they only use Vector so they can keep using Enumeration internally 😕 rather than porting everything over to...idk, Iterable
v
Yes, seems so.
SequenceInputStream
is simply very old and pre-collections framework. I wonder they didn't add a collections variant.
n
no doubt Guava has something similar/better
v
Never used Guava. Isn't it about collections, not about IO streams?
n
yes, but it also has kinda everything. I'm looking