package innovimax.mixthem.io;

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

public class MultiChannelByteReader implements IMultiChannelInputByte {
	
	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<IInputByte> 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 byte[this.readers.size()];
		int channel = 0;
		Iterator<IInputByte> 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<IInputByte> iterator = this.readers.iterator();
		while (iterator.hasNext()) {
			IInputByte reader = iterator.next();
			reader.close();
		}		
	}

}

@@ -191,25 +191,25 @@
 iChannel
+Byte
 Input
-Byte
  %7B%0A%09%0A%09pr
@@ -226,25 +226,24 @@
 l List%3CI
-Input
 Byte
+Inpu
 %3E reader
@@ -261,25 +261,25 @@
 ayList%3CI
+Byte
 Input
-Byte
 %3E();%0A%09%0A%09
@@ -588,33 +588,33 @@
 %09%09Iterator%3CI
+Byte
 Input
-Byte
 %3E iterator =
@@ -670,33 +670,33 @@
 xt()) %7B%0A%09%09%09I
+Byte
 Input
-Byte
  reader = it
@@ -918,33 +918,33 @@
 %09%09Iterator%3CI
+Byte
 Input
-Byte
 %3E iterator =
@@ -1000,33 +1000,33 @@
 xt()) %7B%0A%09%09%09I
+Byte
 Input
-Byte
  reader = it
@@ -1186,25 +1186,25 @@
 erator%3CI
+Byte
 Input
-Byte
 %3E iterat
@@ -1272,17 +1272,17 @@
 %09%09%09I
+Byte
 Input
-Byte
  rea

Update MultiChannelByteReader.java