package innovimax.mixthem.io;

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

public class MultiChannelByteReader implements IMultiInputByte {
	
	private final List<IInputByte> readers = new ArrayList<IInputByte>();
	
	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 {
		Iterator<InputByte> iterator = this.readers.iterator();
		while (iterator.hasNext()) {
			IInputByte reader = iterator.next();
			if (reader.hasByte()) {
				return true;
			}
		}
		return false;
	}
	
	@Override
	public byte[] nextBytes() throws IOException {
		byte[] bytes = new bytes[this.readers.size()];
		int channel = 0;
		Iterator<InputByte> iterator = this.readers.iterator();
		while (iterator.hasNext()) {
			IInputByte reader = iterator.next();
			byte b = reader.nextByte();
			bytes[channel++] = b;
		}
		return bytes;
	}
	
	@Override
	public void close() throws IOException {
		Iterator<InputByte> iterator = this.readers.iterator();
		while (iterator.hasNext()) {
			IInputByte reader = iterator.next();
			reader.close();
		}		
	}

}

@@ -577,32 +577,33 @@
 on %7B%0A%09%09Iterator%3C
+I
 InputByte%3E itera
@@ -862,17 +862,16 @@
 new byte
-s
 %5Bthis.re
@@ -907,32 +907,33 @@
 = 0;%0A%09%09Iterator%3C
+I
 InputByte%3E itera
@@ -1179,16 +1179,17 @@
 terator%3C
+I
 InputByt

Update MultiChannelByteReader.java