package innovimax.mixthem.io;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class MultiChannelByteReader implements IMultiChannelByteInput {
	
	private final List<IByteInput> readers = new ArrayList<IByteInput>();
	
	public MultiChannelByteReader(final List<InputResource> inputs) {
		inputs.stream().forEach(input -> {
			try {
				this.readers.add(new DefaultByteReader(input));
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		});
	}
	
	@Override
	public boolean hasByte() throws IOException {
		final Iterator<IByteInput> iterator = this.readers.iterator();
		while (iterator.hasNext()) {
			final IByteInput reader = iterator.next();
			if (reader.hasByte()) {
				return true;
			}
		}
		return false;
	}
	
	@Override
	public byte[] nextByteRange() throws IOException {
		final byte[] bytes = new byte[this.readers.size()];
		int channel = 0;
		final Iterator<IByteInput> iterator = this.readers.iterator();
		while (iterator.hasNext()) {
			final IByteInput reader = iterator.next();
			final byte b = reader.nextByte();
			bytes[channel++] = b;
		}
		return bytes;
	}
	
	@Override
	public void close() throws IOException {
		final Iterator<IByteInput> iterator = this.readers.iterator();
		while (iterator.hasNext()) {
			final IByteInput reader = iterator.next();
			reader.close();
		}		
	}

}

@@ -345,29 +345,198 @@
 puts
-) %7B%0A%09%09inputs.stream()
+, final Set%3CInteger%3E selection) %7B%0A%09%09try %7B%0A%09%09%09IntStream.range(0, inputs.size())%0A%09%09%09%09.filter(index -%3E selection.contains(Integer.valueOf(index));%0A%09%09%09%09.mapToObj(index -%3E inputs.get(index))%0A%09%09%09%09
 .for
@@ -554,22 +554,26 @@
 -%3E %7B%0A%09%09%09
+%09
+%09
 try %7B%0A
+%09%09
 %09%09%09%09this
@@ -619,16 +619,18 @@
 t));%0A%09%09%09
+%09%09
 %7D catch 
@@ -651,16 +651,18 @@
 ) %7B%0A%09%09%09%09
+%09
+%09
 throw ne
@@ -687,18 +687,22 @@
 (e);%0A%09%09%09
-%7D%0A
+%09%09%7D%0A%09%09
 %09%09%7D);%0A%09%7D

Update MultiChannelByteReader.java