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 {
		Iterator<IByteInput> iterator = this.readers.iterator();
		while (iterator.hasNext()) {
			IByteInput 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<IByteInput> iterator = this.readers.iterator();
		while (iterator.hasNext()) {
			IByteInput reader = iterator.next();
			byte b = reader.nextByte();
			bytes[channel++] = b;
		}
		return bytes;
	}
	
	@Override
	public void close() throws IOException {
		Iterator<IByteInput> iterator = this.readers.iterator();
		while (iterator.hasNext()) {
			IByteInput reader = iterator.next();
			reader.close();
		}		
	}

}

@@ -575,32 +575,38 @@
 IOException %7B%0A%09%09
+final 
 Iterator%3CIByteIn
@@ -672,32 +672,38 @@
 hasNext()) %7B%0A%09%09%09
+final 
 IByteInput reade
@@ -858,16 +858,22 @@
 ion %7B%0A%09%09
+final 
 byte%5B%5D b
@@ -931,16 +931,22 @@
  = 0;%0A%09%09
+final 
 Iterator
@@ -1020,32 +1020,38 @@
 hasNext()) %7B%0A%09%09%09
+final 
 IByteInput reade
@@ -1070,24 +1070,30 @@
 .next();%0A%09%09%09
+final 
 byte b = rea
@@ -1213,16 +1213,22 @@
 ion %7B%0A%09%09
+finla 
 Iterator
@@ -1310,16 +1310,22 @@
 )) %7B%0A%09%09%09
+final 
 IByteInp

Update MultiChannelByteReader.java